X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 478EED1B172 for ; Sat, 19 Jun 2004 07:24:59 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64971-02 for ; Sat, 19 Jun 2004 10:24:54 +0000 (GMT) Received: from ndl1mr1-a-fixed.sancharnet.in (ndl1mr1-a-fixed.sancharnet.in [61.0.0.45]) by svr1.postgresql.org (Postfix) with ESMTP id 89C41D1B169 for ; Sat, 19 Jun 2004 07:24:50 -0300 (ADT) Received: from conversion-daemon.ndl1mr1-a-fixed.sancharnet.in by ndl1mr1-a-fixed.sancharnet.in (iPlanet Messaging Server 5.2 HotFix 1.27 (built May 12 2004)) id <0HZJ00F01WEFR0@ndl1mr1-a-fixed.sancharnet.in> (original mail from sank89@sancharnet.in) for pgsql-sql@postgresql.org; Sat, 19 Jun 2004 15:54:41 +0530 (IST) Received: from [61.0.95.114] by ndl1mr1-a-fixed.sancharnet.in (iPlanet Messaging Server 5.2 HotFix 1.27 (built May 12 2004)) with ESMTPA id <0HZJ00IJHWX32V@ndl1mr1-a-fixed.sancharnet.in>; Sat, 19 Jun 2004 15:54:41 +0530 (IST) Date: Sat, 19 Jun 2004 15:50:05 +0530 From: "V i s h a l Kashyap @ [Sai Hertz And Control Systems]" Subject: Re: case stement when null In-reply-to: To: Jaime Casanova Cc: pgsql-sql@postgresql.org Reply-To: aspire420@hotpop.com Message-id: <40D41355.6010803@sancharnet.in> Organization: Sai Hertz And Control Systems Pvt Ltd MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) References: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.9 tagged_above=0.0 required=5.0 tests=FROM_ENDS_IN_NUMS X-Spam-Level: X-Archive-Number: 200406/163 X-Sequence-Number: 18108 Dear Jaime , > CREATE OR REPLACE FUNCTION > "public"."rec_f_consultarplanificacionrubros" (smallint, smallint, > char(9), smallint, smallint, smallint, char(2)) RETURNS SETOF > "public"."rec_td_rubrosplanificados" AS ' > select rub_codigo, cpa_valor, cpa_fechavencimiento > from rec_m_cuadropagosciclo > where ent_codigo = $1 > and sec_codigo = $2 > and ani_codigo = $3 > and case $4 > when null then cic_codigo IN (select cic_codigo from > aca_m_cicloaniolectivo > where > ent_codigo = $1 > and > sec_codigo = $2 > and > ani_codigo = $3) > else cic_codigo = $4 > end > ' LANGUAGE 'sql' > > but when $4 is null the function executes the else part and what i > want to do is to execute the when null. Can you help me??? > How about this coalesce($4,l (select cic_codigo from aca_m_cicloaniolectivo where ent_codigo = $1 and sec_codigo = $2 and ani_codigo = $3) ) It was a coincidence that I was also working on same kinda query thus I am also in R&D phase more could be found at http://www.varlena.com/varlena/GeneralBits/22.html PostgreSQL documentation talks very less about this i.e with out any example. I would submit a request along with example. -- Regards, Vishal Kashyap Director / Lead Software Developer, Sai Hertz And Control Systems Pvt Ltd, http://saihertz.rediffblogs.com Yahoo IM: mailforvishal[ a t ]yahoo.com