Cc: pgsql-general postgresql(dot)org>. Subject: Re: How to optimize SELECT query with multiple CASE statements?. Good afternoon,. is it please posible to optimize the following SQL query with numerous CASE statements (on same condition!) without. This kind of code perhaps should work for You SELECT *, CASE WHEN (pvc IS NULL OR pvc = '') AND (datepose < ) THEN '01' WHEN. Case statements are useful when you're reaching for an if statement in your select clause. select case when precipitation = 0 then 'none' when precipitation < = 5. In Postgresql, you can use the FILTER clause as follows (untested): SELECT DD_ZIP_CODE, count(*) RECORDS, count(*) filter (where. just add::text to the case when, that is. Select id,case when empid = 1 then blue when empid = 2 then green when empid = 3 then red else. In this tutorial, we will show you how to use the PostgreSQL CASE expression to form conditional query. This PostgreSQL tutorial explains how to use the AND condition and the OR The PostgreSQL AND & OR conditions allow you to test multiple conditions. Hello, This is probably an odd request, but I have my reasons:) Basically, what I need to do is return *multiple* values each for a number of. CASE. The SQL CASE expression is a generic conditional expression, similar to if/else statements in other programming languages: CASE WHEN condition.