Re: Inserting an IF statement in the middle of a SELECT in pl/pgSQL code - Mailing list pgsql-sql

From Jaime Casanova
Subject Re: Inserting an IF statement in the middle of a SELECT in pl/pgSQL code
Date
Msg-id c2d9e70e0707172150j4c319010n17f245c6807aef68@mail.gmail.com
Whole thread Raw
In response to Inserting an IF statement in the middle of a SELECT in pl/pgSQL code  (Norm Garand <indianlakesolutions@rogers.com>)
List pgsql-sql
On 7/17/07, Norm Garand <indianlakesolutions@rogers.com> wrote:
> In the WHERE portion of the SELECT statment, I'd like to insert the IF statement shown below. I've
> tried single and double quotes and the pipeline for concatenation, but nothing seems to work. Any
> suggestions or resolutions would be greatly appreciated. Please feel free to contact me directly.
>

use CASE

baan=# create function t(con_stock boolean) returns setof ttdinv001214 as $$
baan$# select * from ttdinv001214
baan$# where substring(trim(t_item), 1, 3) = 'DPP'
baan$#   and case $1 when true then t_stoc > 0 else t_stoc = 0 end;
baan$# $$ language sql;
CREATE FUNCTION

-- 
regards,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."                                      Richard Cook


pgsql-sql by date:

Previous
From: "Rodrigo De León"
Date:
Subject: Re: Inserting an IF statement in the middle of a SELECT in pl/pgSQL code
Next
From: Norm Garand
Date:
Subject: A better look at trying to insert a Conditional in a SELECT statement