Question about WHERE CASE

From: Mike Martin <redtux1(at)gmail(dot)com>
To: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Question about WHERE CASE
Date: 2019-09-05 11:04:39
Message-ID: CAOwYNKYVz67+qK6QfSiJVhCA8fAXzpHLS-L9HG=SEhOUzJ0A1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have come across the following construct which works in postgres

WHERE CASE WHEN $1=dir THEN TRUE ELSE metadir=$1 END

via (
https://stackoverflow.com/questions/49859153/filter-with-yes-no-and-all-in-postgres
)

case when ('yes'= lower($1)) then (phone_number is not null)
when ('no'=lower($1)) then (phone_number is null)
else true end

I was always under the impression that a case expression could only be
on the right side of a where expression ie:

WHERE fieldname=<cse expression>

Is this a postgres extention, cant find any documentation on this

thanks

Mike

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Martin Stöcker 2019-09-05 11:42:57 Re: Question about WHERE CASE
Previous Message Sebastien FLAESCH 2019-08-30 13:55:35 Re: libpq: How are result sets fetched behind the scene?