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 c2d9e70e0707181940x4cc70527ka211e1789f3f2237@mail.gmail.com
Whole thread Raw
In response to Re: Inserting an IF statement in the middle of a SELECT in pl/pgSQL code  ("Jaime Casanova" <systemguards@gmail.com>)
List pgsql-sql
sorry, i resubmit to the list

On 7/18/07, Jaime Casanova <systemguards@gmail.com> wrote:
> On 7/18/07, Norm Garand <indianlakesolutions@rogers.com> wrote:
> > Thanks Jaime:
> >
> > I tried using the CASE function and it still didn't work.
> >
> > What I need to do is set a conditional, so that if the parameter is NULL, then the this line is
> > ignored completely and of course the opposite applies, if the value is "something", then this line
> > is included in the SELECT. I've just reworded and resubmitted my question and of course, again, I
> > didn't include the facts above. Thanks, for the response, anything is appreciated.
> >
>
> ok, i will do your work...
>
> CREATE OR REPLACE FUNCTION t(con_stock boolean)
>  RETURNS SETOF ttdinv001214 AS
> $BODY$
> select * from ttdinv001214
> where substring(trim(t_item), 1, 3) = 'DPP'
>  and case $1 when true then t_stoc > 0 else 1 = 1 end;
> $BODY$
>  LANGUAGE 'sql' VOLATILE;
>
>
> note the "else 1=1" part, i could be used "else true" or something else
>
> --
> 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
>


-- 
Atentamente,
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: PostgreSQL Admin
Date:
Subject: pgmemcache
Next
From: "Jyoti Seth"
Date:
Subject: Re: Database Synchronization