Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 220A99FB4FB for ; Wed, 18 Jul 2007 23:40:57 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 57886-07 for ; Wed, 18 Jul 2007 23:40:47 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.241]) by postgresql.org (Postfix) with ESMTP id 4B57A9FB4DE for ; Wed, 18 Jul 2007 23:40:53 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c36so84291ana for ; Wed, 18 Jul 2007 19:40:51 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Yf+uJ6tQRRxD8ncad1ivQPDkDCYVsQW0JCJ+/4JW6RFYiAf217uRSoi9cv8Nv0TX9JBlRDbClHVJI9ubgA1bDAQ4D91WiZAznqy6gMQsgzwMKrzhe48thUIropl12ONEl5vGzIjUs5dTXWq6kvlN8YOgu4O7XbLyGeeWdsTwBKY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=hBCUr9VLb/mDAT/kv5PNadwywh1Cf1eAZlRdQhdAE/4vAT9bPwSII5sFqSNsnvMWzxScNZ+6Kw25oruQg8jEKnSTJuULghpyOEjyrqYp9VQxFnfUZ6FXvFFSxLPqr/EZjHJzVtb133kmunLpaSW1Hliz5+HckMYQNCbCHhCt6aM= Received: by 10.100.143.11 with SMTP id q11mr1318681and.1184812851570; Wed, 18 Jul 2007 19:40:51 -0700 (PDT) Received: by 10.100.45.15 with HTTP; Wed, 18 Jul 2007 19:40:51 -0700 (PDT) Message-ID: Date: Wed, 18 Jul 2007 21:40:51 -0500 From: "Jaime Casanova" To: "Norm Garand" Subject: Re: Inserting an IF statement in the middle of a SELECT in pl/pgSQL code Cc: pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <561336.16779.qm@web88309.mail.re4.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/118 X-Sequence-Number: 28853 sorry, i resubmit to the list On 7/18/07, Jaime Casanova wrote: > On 7/18/07, Norm Garand 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