Re: Inserting an IF statement in the middle of a SELECT in pl/pgSQL code

From: "Jaime Casanova" <systemguards(at)gmail(dot)com>
To: "Norm Garand" <indianlakesolutions(at)rogers(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Inserting an IF statement in the middle of a SELECT in pl/pgSQL code
Date: 2007-07-19 02:40:51
Message-ID: c2d9e70e0707181940x4cc70527ka211e1789f3f2237@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

sorry, i resubmit to the list

On 7/18/07, Jaime Casanova <systemguards(at)gmail(dot)com> wrote:
> On 7/18/07, Norm Garand <indianlakesolutions(at)rogers(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jyoti Seth 2007-07-19 04:31:14 Re: Database Synchronization
Previous Message PostgreSQL Admin 2007-07-18 16:46:03 pgmemcache