From jyotiseth2001@gmail.com Fri Feb 22 08:32:00 2008 Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 01DAF2E00CF for ; Fri, 22 Feb 2008 04:32:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 28884-05 for ; Fri, 22 Feb 2008 04:31:53 -0400 (AST) Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.190]) by postgresql.org (Postfix) with ESMTP id 43BD82E005B for ; Fri, 22 Feb 2008 04:31:56 -0400 (AST) Received: by rv-out-0910.google.com with SMTP id g13so235348rvb.43 for ; Fri, 22 Feb 2008 00:31:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date:message-id:mime-version:content-type:x-mailer:thread-index:content-language; bh=B0xya9JM5iNSz+kFOKu6Oi5tG3j8ckOxlVm9QQT9ZrQ=; b=gFkXFDIvC59bEcKjMjHdrqnT14GXSapbs/96lBsgMj8MvwtVjXqSKubCwDyLDbjD5Tr1Dp634K17UIuqq9USr8876kHvRi4TyICN4OUScAC5g5T+lDOnf8K7ucAgqEeWVhgrNeDsxspxxlZu41AIBDss0A3gMKPhpVfJIQgBH3M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:mime-version:content-type:x-mailer:thread-index:content-language; b=iVq4DYx/2LkEMnInd43b9M/JKZDLi041sQxu2X784N+cUgVrC9FLye26iFFlJbQEc/hRHYrG8cPXO9JgCnGpdgZo6AxB5NlMrVLlYdIC0t3q+N73ZiewYYqDS7igyys0wDMbgE3lPghDKzsUd2IXhjZwPZNMTw3sq5o3KfPg3j8= Received: by 10.140.139.3 with SMTP id m3mr7414070rvd.244.1203669115154; Fri, 22 Feb 2008 00:31:55 -0800 (PST) Received: from BITDLLT03 ( [122.162.21.57]) by mx.google.com with ESMTPS id c20sm2286537rvf.33.2008.02.22.00.31.52 (version=SSLv3 cipher=RC4-MD5); Fri, 22 Feb 2008 00:31:53 -0800 (PST) From: "Jyoti Seth" To: Subject: postgresql function not accepting null values in select statement Date: Fri, 22 Feb 2008 14:00:42 +0530 Message-ID: <001501c8752d$391c8e50$ab55aaf0$@com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0016_01C8755B.52D4CA50" X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ach1LTYOwQqhq33wRo2PYdHp74qGiw== Content-Language: en-us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/158 X-Sequence-Number: 30249 This is a multipart message in MIME format. ------=_NextPart_000_0016_01C8755B.52D4CA50 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, If I pass null value as the parameter of postgresql function, which is used in the where clause of select statement is not functioning properly. I have also changed the value of transform_null_equals = on in the conf file and restarted postgresql. But it is still giving error. Is there any possible solution. Thanks, Jyoti ------=_NextPart_000_0016_01C8755B.52D4CA50 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

 

If I pass null value as the parameter of postgresql = function, which is used in the where clause of select statement is not functioning properly.

 

I have also changed the value of transform_null_equals =3D = on in the conf file and restarted postgresql. But it is still giving error. =

 

Is there any possible solution.

 

Thanks,

Jyoti

------=_NextPart_000_0016_01C8755B.52D4CA50-- From dev@archonet.com Fri Feb 22 09:05:42 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 613792E0160 for ; Fri, 22 Feb 2008 05:05:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 68045-07 for ; Fri, 22 Feb 2008 05:05:30 -0400 (AST) Received: from pih-relay06.plus.net (pih-relay06.plus.net [212.159.14.133]) by postgresql.org (Postfix) with ESMTP id 520292E0158 for ; Fri, 22 Feb 2008 05:05:30 -0400 (AST) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay06.plus.net with esmtp (Exim) id 1JSTqT-0007TM-0o; Fri, 22 Feb 2008 09:05:29 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id B73B6274057; Fri, 22 Feb 2008 09:05:28 +0000 (GMT) Message-ID: <47BE9058.9030909@archonet.com> Date: Fri, 22 Feb 2008 09:05:28 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.9 (X11/20071031) MIME-Version: 1.0 To: Jyoti Seth CC: pgsql-sql@postgresql.org Subject: Re: postgresql function not accepting null values in select statement References: <001501c8752d$391c8e50$ab55aaf0$@com> In-Reply-To: <001501c8752d$391c8e50$ab55aaf0$@com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: d415406030b01697c0e9cc2a47b51c94 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/159 X-Sequence-Number: 30250 Jyoti Seth wrote: > > If I pass null value as the parameter of postgresql function, which is used > in the where clause of select statement is not functioning properly. Either: 1. You're talking about frooble(), in which case it's supposed to do that. or 2. You'll need to tell us what function it is, how you're using it and what you think should happen. My guess is that you're getting a null as the result and that's not doing what you'd expect in your where clause. -- Richard Huxton Archonet Ltd From jyotiseth2001@gmail.com Fri Feb 22 09:24:29 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id D9FE62E015C for ; Fri, 22 Feb 2008 05:24:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 80632-06 for ; Fri, 22 Feb 2008 05:24:11 -0400 (AST) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.227]) by postgresql.org (Postfix) with ESMTP id 52FDE2E00F1 for ; Fri, 22 Feb 2008 05:24:11 -0400 (AST) Received: by wx-out-0506.google.com with SMTP id r21so312589wxc.28 for ; Fri, 22 Feb 2008 01:24:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:references:in-reply-to:subject:date:message-id:mime-version:content-type:content-transfer-encoding:x-mailer:thread-index:content-language; bh=dLjHENIYUe8O4ehkJ/WhFBC2FAMcvbfMsWPC2OhpkzE=; b=g274quhwUp71Ms24uoHyTJlY3ijCumbizJ7hHRTBuBVaFc2sD44NYhUOgFWVFLsKz0iSiKJ8g1YRUYdXXGDsYYGgJ7S3d8SwKpXBT1+cxNYN7hGua8LJV0KtE9XttY8ppLupWRShWTP8kGTKFStp+cVPOulFjNyh9Qy39JHiba8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:references:in-reply-to:subject:date:message-id:mime-version:content-type:content-transfer-encoding:x-mailer:thread-index:content-language; b=sQDfUgJGgNjfj9PmejrZFPWEI0X09de2NRBRejRp9t6PSDawKExpMjNfRr6InOI3RAOH8ArOdzbWj594woAj/hYehJBo7/hQeYEes6hls5dxK9SS7yTtuoUzXCcpx1u2LEnX54lU55vROJlDBUKUenmu3PGq9ijlEN8S/Ptbr7Y= Received: by 10.141.205.10 with SMTP id h10mr7456662rvq.138.1203672249458; Fri, 22 Feb 2008 01:24:09 -0800 (PST) Received: from BITDLLT03 ( [122.162.21.57]) by mx.google.com with ESMTPS id f34sm2262062rvb.3.2008.02.22.01.24.06 (version=SSLv3 cipher=RC4-MD5); Fri, 22 Feb 2008 01:24:08 -0800 (PST) From: "Jyoti Seth" To: "'Richard Huxton'" Cc: References: <001501c8752d$391c8e50$ab55aaf0$@com> <47BE9058.9030909@archonet.com> In-Reply-To: <47BE9058.9030909@archonet.com> Subject: Re: postgresql function not accepting null values in select statement Date: Fri, 22 Feb 2008 14:52:55 +0530 Message-ID: <001a01c87534$84eea280$8ecbe780$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ach1MhKL0i37PpGHRTWySgRUF20FmAAASc6Q Content-Language: en-us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/160 X-Sequence-Number: 30251 Hi, I have a the following procedure CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) RETURNS SETOF t_functionaries AS $BODY$ DECLARE rec t_functionaries%ROWTYPE; begin FOR rec IN SELECT f.functionaryid, f.category,f.description FROM functionaries f where f.statecd=p_statecd LOOP return next rec; END LOOP; return; end; $BODY$ LANGUAGE 'plpgsql' VOLATILE; In the functionaries table statecd is a null field. When I pass some integer value to the above procedure it works correctly but if I pass null value in p_statecd it doesn't show anything whereas it has values and if I write the select statement separately it gives values Thanks, Jyoti -----Original Message----- From: Richard Huxton [mailto:dev@archonet.com] Sent: Friday, February 22, 2008 2:35 PM To: Jyoti Seth Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] postgresql function not accepting null values in select statement Jyoti Seth wrote: > > If I pass null value as the parameter of postgresql function, which is used > in the where clause of select statement is not functioning properly. Either: 1. You're talking about frooble(), in which case it's supposed to do that. or 2. You'll need to tell us what function it is, how you're using it and what you think should happen. My guess is that you're getting a null as the result and that's not doing what you'd expect in your where clause. -- Richard Huxton Archonet Ltd From dev@archonet.com Fri Feb 22 09:34:06 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 397FA2E00C5 for ; Fri, 22 Feb 2008 05:34:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 84810-04 for ; Fri, 22 Feb 2008 05:34:03 -0400 (AST) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by postgresql.org (Postfix) with ESMTP id AB00F2E00D5 for ; Fri, 22 Feb 2008 05:34:03 -0400 (AST) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by ptb-relay03.plus.net with esmtp (Exim) id 1JSUI6-00049f-EE; Fri, 22 Feb 2008 09:34:02 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 1A8D0274053; Fri, 22 Feb 2008 09:33:59 +0000 (GMT) Message-ID: <47BE9707.3060109@archonet.com> Date: Fri, 22 Feb 2008 09:33:59 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.9 (X11/20071031) MIME-Version: 1.0 To: Jyoti Seth CC: pgsql-sql@postgresql.org Subject: Re: postgresql function not accepting null values in select statement References: <001501c8752d$391c8e50$ab55aaf0$@com> <47BE9058.9030909@archonet.com> <001a01c87534$84eea280$8ecbe780$@com> In-Reply-To: <001a01c87534$84eea280$8ecbe780$@com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: 9c640484384e9d4c308d79b2ac7cfd5e X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/161 X-Sequence-Number: 30252 Jyoti Seth wrote: > Hi, > > I have a the following procedure > > CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) > SELECT f.functionaryid, f.category,f.description > FROM functionaries f > where f.statecd=p_statecd > In the functionaries table statecd is a null field. When I pass some integer > value to the above procedure it works correctly but if I pass null value in > p_statecd it doesn't show anything whereas it has values and if I write the > select statement separately it gives values You can't be getting results from a query WHERE statecd = NULL, because NULL = NULL returns NULL, which is equivalent to false in a WHERE clause. If you want to check for NULL you need to use statecd IS NULL, but if you are treating it like a value then you're using it incorrectly. -- Richard Huxton Archonet Ltd From tharakan@gmail.com Fri Feb 22 09:34:12 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 21CBA2E00E6 for ; Fri, 22 Feb 2008 05:34:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 83021-10 for ; Fri, 22 Feb 2008 05:34:08 -0400 (AST) Received: from hu-out-0506.google.com (hu-out-0506.google.com [72.14.214.238]) by postgresql.org (Postfix) with ESMTP id 63D482E00D5 for ; Fri, 22 Feb 2008 05:34:08 -0400 (AST) Received: by hu-out-0506.google.com with SMTP id 22so393272hug.23 for ; Fri, 22 Feb 2008 01:34:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=JG4QnxpkRIF15Y/8UDCRabtU0xNP0Hy8HEnOAiK/Fvs=; b=pWi02frFpLCVNmJAroFvI+EPt7IY5nmLOMbXxr7dRamBiT2JJgNRqk0P7UhpMonjRBpesHv5XBSMb0tCt/Aptq9oO6iyTv5dH9wzuyYDiZlEfxPy1ypBiwCOyjw4/jZ2vKUWcRrapd/uFxqIMJXGIGD/N67faf1Uft6LoLY76Yc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=OCrMCp8jHd6mMZQgoCyOFsPLox9KuaRcKiAXYTlgRNacV88jLx4L+8o85fVvZo/ZxUDpP1sQhG+eFHD2/ZRnYziSlIchgbT/0IhHA9NNsxA2cbMD7M9CdEP83rxj/Xat7NUk3tLl5h4Gp7E1TKoV3ClTXPqudaoMAT+WpS25OWA= Received: by 10.82.166.9 with SMTP id o9mr19059706bue.34.1203672846854; Fri, 22 Feb 2008 01:34:06 -0800 (PST) Received: by 10.82.112.18 with HTTP; Fri, 22 Feb 2008 01:34:06 -0800 (PST) Message-ID: <36af4bed0802220134n12831a64l6fce1364f53f8598@mail.gmail.com> Date: Fri, 22 Feb 2008 15:04:06 +0530 From: "Robins Tharakan" To: pgsql-sql Subject: Re: postgresql function not accepting null values in select statement In-Reply-To: <36af4bed0802220132k613126b3la36f26d10fdaaad3@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_332_31741800.1203672846847" References: <001501c8752d$391c8e50$ab55aaf0$@com> <47BE9058.9030909@archonet.com> <001a01c87534$84eea280$8ecbe780$@com> <36af4bed0802220132k613126b3la36f26d10fdaaad3@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/162 X-Sequence-Number: 30253 ------=_Part_332_31741800.1203672846847 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > > Hi, > > When you pass non-null values in p_statecd the result should work fine, > but when you pass NULL in p_statecd ... the equal operator stops to work as > you as expect it to. > > Please see this documentation: > http://www.postgresql.org/docs/8.2/interactive/functions-comparison.html > from where I quote: "Do *not* write *expression* = NULL because NULL is > not "equal to" NULL. (The null value represents an unknown value, and it > is not known whether two unknown values are equal.) This behavior conforms > to the SQL standard." > > As the document suggests you may want to try this way out: > > .... WHERE f.statecd IS NOT DISTINCT FROM p_statecd > > This would take care of both NULL and non-NULL values. > > *Robins* > > > ---------- Forwarded message ---------- > From: Jyoti Seth > Date: Fri, Feb 22, 2008 at 2:52 PM > Subject: Re: [SQL] postgresql function not accepting null values in select > statement > To: Richard Huxton > Cc: pgsql-sql@postgresql.org > > > Hi, > > I have a the following procedure > > CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) > RETURNS SETOF t_functionaries AS > $BODY$ > DECLARE rec t_functionaries%ROWTYPE; > begin > FOR rec IN > SELECT f.functionaryid, f.category,f.description > FROM functionaries f > where f.statecd=p_statecd > > LOOP > return next rec; > END LOOP; > return; > end; > $BODY$ > LANGUAGE 'plpgsql' VOLATILE; > > In the functionaries table statecd is a null field. When I pass some > integer > value to the above procedure it works correctly but if I pass null value > in > p_statecd it doesn't show anything whereas it has values and if I write > the > select statement separately it gives values > > Thanks, > Jyoti > > -----Original Message----- > From: Richard Huxton [mailto:dev@archonet.com] > Sent: Friday, February 22, 2008 2:35 PM > To: Jyoti Seth > Cc: pgsql-sql@postgresql.org > Subject: Re: [SQL] postgresql function not accepting null values in select > statement > > Jyoti Seth wrote: > > > > If I pass null value as the parameter of postgresql function, which is > used > > in the where clause of select statement is not functioning properly. > > Either: > > 1. You're talking about frooble(), in which case it's supposed to do that. > > or > > 2. You'll need to tell us what function it is, how you're using it and > what you think should happen. > > My guess is that you're getting a null as the result and that's not > doing what you'd expect in your where clause. > > > -- > Richard Huxton > Archonet Ltd > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > > ------=_Part_332_31741800.1203672846847 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Hi,

When you pass non-null values in p_statecd the result should work fine, but when you pass NULL in p_statecd ... the equal operator stops to work as you as expect it to.

Please see this documentation: http://www.postgresql.org/docs/8.2/interactive/functions-comparison.html
from where I quote: "Do not write expression = NULL because NULL is not "equal to" NULL. (The null value represents an unknown value, and it is not known whether two unknown values are equal.) This behavior conforms to the SQL standard."

As the document suggests you may want to try this way out:

.... WHERE f.statecd IS NOT DISTINCT FROM p_statecd

This would take care of both NULL and non-NULL values.

Robins


---------- Forwarded message ----------
From: Jyoti Seth <jyotiseth2001@gmail.com>
Date: Fri, Feb 22, 2008 at 2:52 PM
Subject: Re: [SQL] postgresql function not accepting null values in select statement
To: Richard Huxton <dev@archonet.com>
Cc: pgsql-sql@postgresql.org


Hi,

I have a the following procedure

CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer)
 RETURNS SETOF t_functionaries AS
$BODY$
DECLARE rec t_functionaries%ROWTYPE;
begin
      FOR rec IN
       SELECT f.functionaryid, f.category,f.description
       FROM functionaries f
    where f.statecd=p_statecd

       LOOP
       return next rec;
       END LOOP;
      return;
  end;
$BODY$
 LANGUAGE 'plpgsql' VOLATILE;

In the functionaries table statecd is a null field. When I pass some integer
value to the above procedure it works correctly but if I pass null value in
p_statecd it doesn't show anything whereas it has values and if I write the
select statement separately it gives values

Thanks,
Jyoti

-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com]
Sent: Friday, February 22, 2008 2:35 PM
To: Jyoti Seth
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] postgresql function not accepting null values in select
statement

Jyoti Seth wrote:
>
> If I pass null value as the parameter of postgresql function, which is
used
> in the where clause of select statement is not functioning properly.

Either:

1. You're talking about frooble(), in which case it's supposed to do that.

or

2. You'll need to tell us what function it is, how you're using it and
what you think should happen.

My guess is that you're getting a null as the result and that's not
doing what you'd expect in your where clause.


--
  Richard Huxton
  Archonet Ltd


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


------=_Part_332_31741800.1203672846847-- From Bart.Degryse@indicator.be Fri Feb 22 09:36:00 2008 Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 3B1AA2E00BB for ; Fri, 22 Feb 2008 05:36:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 90406-02 for ; Fri, 22 Feb 2008 05:35:52 -0400 (AST) Received: from interscan.indicator.com (mail.indicator.be [193.121.199.3]) by postgresql.org (Postfix) with ESMTP id 2174E2E00F6 for ; Fri, 22 Feb 2008 05:35:55 -0400 (AST) Received: from DOMEXT-MTA by webaccess.indicator.bewith Novell_GroupWise; Fri, 22 Feb 2008 10:35:53 +0100 Message-Id: <47BEA582.A3DD.0030.0@indicator.be> X-Mailer: Novell GroupWise Internet Agent 7.0.1 Date: Fri, 22 Feb 2008 10:35:47 +0100 From: "Bart Degryse" To: "'Richard Huxton'" , "Jyoti Seth" Cc: Subject: Re: postgresql function not accepting null values inselect statement References: <001501c8752d$391c8e50$ab55aaf0$@com><47BE9058.9030909@archonet.com> <001a01c87534$84eea280$8ecbe780$@com> In-Reply-To: <001a01c87534$84eea280$8ecbe780$@com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=__Part65439163.2__=" X-imss-version: 2.050 X-imss-result: Passed X-imss-approveListMatch: *@indicator.be X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/163 X-Sequence-Number: 30254 --=__Part65439163.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Can you try this... =20 CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) RETURNS SETOF t_functionaries AS $BODY$ DECLARE rec t_functionaries%ROWTYPE;=20 BEGIN FOR rec IN ( SELECT f.functionaryid, f.category, f.description FROM functionaries f WHERE f.statecd IS NOT DISTINCT FROM p_statecd) LOOP return next rec; END LOOP; return; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; >>> "Jyoti Seth" 2008-02-22 10:22 >>> Hi, I have a the following procedure=20 CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) RETURNS SETOF t_functionaries AS $BODY$ DECLARE rec t_functionaries%ROWTYPE;=20 begin FOR rec IN=20 SELECT f.functionaryid, f.category,f.description FROM functionaries f where f.statecd=3Dp_statecd LOOP return next rec; END LOOP; return; end; $BODY$ LANGUAGE 'plpgsql' VOLATILE; In the functionaries table statecd is a null field. When I pass some = integer value to the above procedure it works correctly but if I pass null value = in p_statecd it doesn't show anything whereas it has values and if I write = the select statement separately it gives values Thanks, Jyoti -----Original Message----- From: Richard Huxton [mailto:dev@archonet.com]=20 Sent: Friday, February 22, 2008 2:35 PM To: Jyoti Seth Cc: pgsql-sql@postgresql.org=20 Subject: Re: [SQL] postgresql function not accepting null values in select statement Jyoti Seth wrote: >=20 > If I pass null value as the parameter of postgresql function, which is used > in the where clause of select statement is not functioning properly. Either: 1. You're talking about frooble(), in which case it's supposed to do that. or 2. You'll need to tell us what function it is, how you're using it and=20 what you think should happen. My guess is that you're getting a null as the result and that's not=20 doing what you'd expect in your where clause. --=20 Richard Huxton Archonet Ltd ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend --=__Part65439163.2__= Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Description: HTML
Can you try this...
 
CREATE OR REPLACE FUNCTION getfunctionaries= (p_statecd integer)
  RETURNS SETOF t_functionaries AS
$BODY$DECLARE
  rec t_functionaries%ROWTYPE; BEGIN
  FOR rec IN (
    SELECT = f.functionaryid, f.category, f.description
    FROM = functionaries f
    WHERE f.statecd IS NOT DISTINCT = FROM p_statecd)
  LOOP
    return next = rec;
  END LOOP;
  return;
END;
$BODY$
LANGUAGE = 'plpgsql' VOLATILE;

>>> "Jyoti Seth" <jyotiseth20= 01@gmail.com> 2008-02-22 10:22 >>>
Hi,

I have a the = following procedure

CREATE OR REPLACE FUNCTION getfunctionaries(p_s= tatecd integer)
  RETURNS SETOF t_functionaries AS
$BODY$
DEC= LARE rec t_functionaries%ROWTYPE;
begin
    &nbs= p;  FOR rec IN
SELECT f.functionaryid, f.category,f.descriptionFROM functionaries f
     where f.statecd=3Dp_state= cd

LOOP
        return next = rec;
        END LOOP;
  = ;     return;
   end;
$BODY$
  = LANGUAGE 'plpgsql' VOLATILE;

In the functionaries table statecd is = a null field. When I pass some integer
value to the above procedure it = works correctly but if I pass null value in
p_statecd it doesn't show = anything whereas it has values and if I write the
select statement = separately it gives values

Thanks,
Jyoti

-----Original = Message-----
From: Richard Huxton [mailto:dev@archonet.com]
Sent: = Friday, February 22, 2008 2:35 PM
To: Jyoti Seth
Cc: pgsql-sql@postgr= esql.org
Subject: Re: [SQL] postgresql function not accepting null = values in select
statement

Jyoti Seth wrote:
>
> If = I pass null value as the parameter of postgresql function, which is
used=
> in the where clause of select statement is not functioning = properly.

Either:

1. You're talking about frooble(), in = which case it's supposed to do that.

or

2. You'll need to = tell us what function it is, how you're using it and
what you think = should happen.

My guess is that you're getting a null as the result = and that's not
doing what you'd expect in your where clause.

--
   Richard Huxton
   Archonet Ltd

---------------------------(end of broadcast)---------------------------TIP 6: explain analyze is your friend
--=__Part65439163.2__=-- From jfabiani@yolo.com Fri Feb 22 22:01:52 2008 Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 8755E2E00F7 for ; Fri, 22 Feb 2008 18:01:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 50905-03 for ; Fri, 22 Feb 2008 18:01:45 -0400 (AST) X-Greylist: delayed 02:35:49.485619 by SQLgrey-1.7.5 Received: from que03.charter.net (que03.charter.net [209.225.8.191]) by postgresql.org (Postfix) with ESMTP id BA44D2E00F9 for ; Fri, 22 Feb 2008 18:01:49 -0400 (AST) Received: from aarprv06.charter.net ([10.20.200.76]) by mta12.charter.net (InterMail vM.7.08.03.00 201-2186-126-20070710) with ESMTP id <20080222163102.HSPI22287.mta12.charter.net@aarprv06.charter.net> for ; Fri, 22 Feb 2008 11:31:02 -0500 Received: from [192.168.1.215] (really [68.186.33.18]) by aarprv06.charter.net with ESMTP id <20080222163102.IPZE14098.aarprv06.charter.net@[192.168.1.215]> for ; Fri, 22 Feb 2008 11:31:02 -0500 From: johnf To: pgsql-sql@postgresql.org Subject: Re: postgresql function not accepting null values inselect statement Date: Fri, 22 Feb 2008 08:30:56 -0800 User-Agent: KMail/1.9.6 (enterprise 20070904.708012) References: <001501c8752d$391c8e50$ab55aaf0$@com> <001a01c87534$84eea280$8ecbe780$@com> <47BEA582.A3DD.0030.0@indicator.be> In-Reply-To: <47BEA582.A3DD.0030.0@indicator.be> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802220830.56917.jfabiani@yolo.com> X-Chzlrs: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/167 X-Sequence-Number: 30258 On Friday 22 February 2008 01:35:47 am Bart Degryse wrote: > Can you try this... > > CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) > RETURNS SETOF t_functionaries AS > $BODY$ > DECLARE > rec t_functionaries%ROWTYPE; > BEGIN > FOR rec IN ( > SELECT f.functionaryid, f.category, f.description > FROM functionaries f > WHERE f.statecd IS NOT DISTINCT FROM p_statecd) > LOOP > return next rec; > END LOOP; > return; > END; > $BODY$ > LANGUAGE 'plpgsql' VOLATILE; > a newbie question. Could you explain why yours works? I don't understand how it works if p_statecd = NULL -- John Fabiani From jyotiseth2001@gmail.com Mon Feb 25 05:37:23 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 999662E00C4 for ; Mon, 25 Feb 2008 01:37:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 11868-07 for ; Mon, 25 Feb 2008 01:37:21 -0400 (AST) X-Greylist: delayed 00:15:50.160263 by SQLgrey-1.7.5 Received: from po-out-1718.google.com (po-out-1718.google.com [72.14.252.158]) by postgresql.org (Postfix) with ESMTP id 39FC32E00E7 for ; Mon, 25 Feb 2008 01:37:21 -0400 (AST) Received: by po-out-1718.google.com with SMTP id c31so2575086poi.3 for ; Sun, 24 Feb 2008 21:37:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:references:in-reply-to:subject:date:message-id:mime-version:content-type:content-transfer-encoding:x-mailer:thread-index:content-language; bh=4nMCzq2/rY13vpUpe+aNUBlD5GQLbMJ5ct5/OAxwWCo=; b=QLwAvAe+1X1mpWfF1cWVcqTQTpkzIdLjVgGe+x2BgAwdDPVSWvDEpzMtJTfk2qVYmxMnJmFxQBMjmX6OIQQ4H+bg5K9RKUPJqEh8vCSY0k2eDcjC15EIOesY5K5r7+pzRwi332bXkHjrhi80GRRQnJIKzqOeMLJBJsVYxZKY6Zc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:references:in-reply-to:subject:date:message-id:mime-version:content-type:content-transfer-encoding:x-mailer:thread-index:content-language; b=aG3u7i7qYQ9a7jsDmjuSu3aXLdrqglpVHnzXumKpl8OHDUDRkwTopcVRJAEtN64kkotN5egJPbP1VszyinQRcsy5VP+ZmDl6gRX/hRwt/FYW9o32zzbg1Hkod+EHAvhxBg+XL4W2WVATeA5U6OltJwHo++RxEl2lsB7NUmiu/ZY= Received: by 10.141.164.13 with SMTP id r13mr1706325rvo.90.1203916889983; Sun, 24 Feb 2008 21:21:29 -0800 (PST) Received: from BITDLLT03 ( [122.162.21.57]) by mx.google.com with ESMTPS id k41sm11061524rvb.24.2008.02.24.21.21.25 (version=SSLv3 cipher=RC4-MD5); Sun, 24 Feb 2008 21:21:28 -0800 (PST) From: "Jyoti Seth" To: "'johnf'" Cc: References: <001501c8752d$391c8e50$ab55aaf0$@com> <001a01c87534$84eea280$8ecbe780$@com> <47BEA582.A3DD.0030.0@indicator.be> <200802220830.56917.jfabiani@yolo.com> In-Reply-To: <200802220830.56917.jfabiani@yolo.com> Subject: Re: postgresql function not accepting null values inselect statement Date: Mon, 25 Feb 2008 10:50:04 +0530 Message-ID: <002401c8776e$17698b80$463ca280$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ach1nrdDgaqBWtTrQ0+nnKPizG0hZwBzzdXA Content-Language: en-us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/176 X-Sequence-Number: 30267 I have tried this, but it is showing following error: ERROR: syntax error at or near "DISTINCT" SQL state: 42601 Thanks, Jyoti -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of johnf Sent: Friday, February 22, 2008 10:01 PM To: pgsql-sql@postgresql.org Subject: Re: [SQL] postgresql function not accepting null values inselect statement On Friday 22 February 2008 01:35:47 am Bart Degryse wrote: > Can you try this... > > CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) > RETURNS SETOF t_functionaries AS > $BODY$ > DECLARE > rec t_functionaries%ROWTYPE; > BEGIN > FOR rec IN ( > SELECT f.functionaryid, f.category, f.description > FROM functionaries f > WHERE f.statecd IS NOT DISTINCT FROM p_statecd) > LOOP > return next rec; > END LOOP; > return; > END; > $BODY$ > LANGUAGE 'plpgsql' VOLATILE; > a newbie question. Could you explain why yours works? I don't understand how it works if p_statecd = NULL -- John Fabiani ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings From tharakan@gmail.com Mon Feb 25 07:14:28 2008 Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id C1C3F2E01BC for ; Mon, 25 Feb 2008 03:14:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 34016-01-9 for ; Mon, 25 Feb 2008 03:14:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from hu-out-0506.google.com (hu-out-0506.google.com [72.14.214.229]) by postgresql.org (Postfix) with ESMTP id A14C12E014F for ; Mon, 25 Feb 2008 03:12:40 -0400 (AST) Received: by hu-out-0506.google.com with SMTP id 22so1840142hug.23 for ; Sun, 24 Feb 2008 23:12:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=cv1K25nHTnlZObh4XFUTi5EBl06J3BdpLC9SiteWUTE=; b=XXkePVv24Wb4Wm852XM3pgiBDMKA0cYRVjub4yC47Z50+75VCIm7/pAkJQdwy7tCCbMRdj65NaASxtTIL//cCH/KRjIv5HudtcSDomspc3E2aOh6JRhe4oRZJEHUVMreYwlJN5kkipxCEql5wAqovSm48x4bi8Ym060iYBkPHuY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=L2hTMXxNMewkDQc6hngf36sppD+4qvXe21axF37gBLn6m2109LdPc+KSLzDowzVRbXI+Qxnwd3atmJC0D0FOdxTaUKdvinh0C7fen9KlAcNAAUpYGKv23ucq0piVIWu1zNgQSHUMnh+4jc2VLEhWtXLIjIBzzEybjfM4H1gXxaE= Received: by 10.82.146.10 with SMTP id t10mr5039716bud.8.1203922595337; Sun, 24 Feb 2008 22:56:35 -0800 (PST) Received: by 10.82.112.18 with HTTP; Sun, 24 Feb 2008 22:56:35 -0800 (PST) Message-ID: <36af4bed0802242256i7f0e7a36i4f0cf4b567dfadc2@mail.gmail.com> Date: Mon, 25 Feb 2008 12:26:35 +0530 From: "Robins Tharakan" To: pgsql-sql@postgresql.org Subject: Re: postgresql function not accepting null values inselect statement In-Reply-To: <36af4bed0802242256g7dd98934mc7bdbba1a6bf33b3@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_13196_17691776.1203922595329" References: <001501c8752d$391c8e50$ab55aaf0$@com> <001a01c87534$84eea280$8ecbe780$@com> <47BEA582.A3DD.0030.0@indicator.be> <200802220830.56917.jfabiani@yolo.com> <002401c8776e$17698b80$463ca280$@com> <36af4bed0802242256g7dd98934mc7bdbba1a6bf33b3@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/180 X-Sequence-Number: 30271 ------=_Part_13196_17691776.1203922595329 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > > What version of PostGreSQL are you using ? > Are you sure there was no typing error ? This SQL should work in the most > recent version of PG.( at least version 8.1 onwards) > > *Robins* > > > On Mon, Feb 25, 2008 at 10:50 AM, Jyoti Seth > wrote: > > > I have tried this, but it is showing following error: > > ERROR: syntax error at or near "DISTINCT" > > SQL state: 42601 > > > > Thanks, > > Jyoti > > > > > > -----Original Message----- > > From: pgsql-sql-owner@postgresql.org [mailto: > > pgsql-sql-owner@postgresql.org] > > On Behalf Of johnf > > Sent: Friday, February 22, 2008 10:01 PM > > To: pgsql-sql@postgresql.org > > Subject: Re: [SQL] postgresql function not accepting null values > > inselect > > statement > > > > On Friday 22 February 2008 01:35:47 am Bart Degryse wrote: > > > Can you try this... > > > > > > CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) > > > RETURNS SETOF t_functionaries AS > > > $BODY$ > > > DECLARE > > > rec t_functionaries%ROWTYPE; > > > BEGIN > > > FOR rec IN ( > > > SELECT f.functionaryid, f.category, f.description > > > FROM functionaries f > > > WHERE f.statecd IS NOT DISTINCT FROM p_statecd) > > > LOOP > > > return next rec; > > > END LOOP; > > > return; > > > END; > > > $BODY$ > > > LANGUAGE 'plpgsql' VOLATILE; > > > > > a newbie question. Could you explain why yours works? I don't > > understand > > how > > it works if p_statecd = NULL > > > > > > -- > > John Fabiani > > > > ---------------------------(end of broadcast)--------------------------- > > TIP 5: don't forget to increase your free space map settings > > > > > > ---------------------------(end of broadcast)--------------------------- > > TIP 4: Have you searched our list archives? > > > > http://archives.postgresql.org > > > > ------=_Part_13196_17691776.1203922595329 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
What version of PostGreSQL are you using ?
Are you sure there was no typing error ? This SQL should work in the most recent version of PG.( at least version 8.1 onwards)

Robins


On Mon, Feb 25, 2008 at 10:50 AM, Jyoti Seth <jyotiseth2001@gmail.com> wrote:
I have tried this, but it is showing following error:
ERROR: syntax error at or near "DISTINCT"
SQL state: 42601

Thanks,
Jyoti


-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of johnf
Sent: Friday, February 22, 2008 10:01 PM
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] postgresql function not accepting null values inselect
statement

On Friday 22 February 2008 01:35:47 am Bart Degryse wrote:
> Can you try this...
>
> CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer)
>   RETURNS SETOF t_functionaries AS
> $BODY$
> DECLARE
>   rec t_functionaries%ROWTYPE;
> BEGIN
>   FOR rec IN (
>     SELECT f.functionaryid, f.category, f.description
>     FROM functionaries f
>     WHERE f.statecd IS NOT DISTINCT FROM p_statecd)
>   LOOP
>     return next rec;
>   END LOOP;
>   return;
> END;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
>
a newbie question.  Could you explain why yours works?  I don't understand
how
it works if p_statecd = NULL


--
John Fabiani

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org


------=_Part_13196_17691776.1203922595329-- From tharakan@gmail.com Mon Feb 25 07:03:13 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 9030E2E002E for ; Mon, 25 Feb 2008 03:03:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 47934-02 for ; Mon, 25 Feb 2008 03:03:10 -0400 (AST) X-Greylist: delayed 00:06:55.882811 by SQLgrey-1.7.5 Received: from hu-out-0506.google.com (hu-out-0506.google.com [72.14.214.239]) by postgresql.org (Postfix) with ESMTP id 3D9262E010A for ; Mon, 25 Feb 2008 03:03:09 -0400 (AST) Received: by hu-out-0506.google.com with SMTP id 22so1838836hug.23 for ; Sun, 24 Feb 2008 23:03:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=Pxh0H+bWwRGU5+0NDs6TwugsNT7zTWhPona/6l0usiw=; b=HZiszxGrVDjEhZLkWXFMbiht6uye2dvTXecGJqqwCI5AN54BB8WHsIld1NMuosE6xt5JocVoKI/77l41+eutCFX+7GykeOQMR3NA8l4/Ccdb5XKDnsa/DskgpGXp4BQu6Y/8AeAjHgw9leWo6kvQErN5lGinJOC0/Tf+Y1zY5x8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=avNJ7dL3NPURjxfh8qCowEPxdKoJ27MaEly2lrU3t9TWdbVrHYuG2cFFTdve0X06gxY+LyUbDmkqap6paAlN3EVjDq+bPrNjweIcikunrW4MpihEqCQEotttdZUfYM/szkLKONI95ceFeV5SIoBDoa9k5NBvnoNaN35IV4HF1FQ= Received: by 10.82.112.3 with SMTP id k3mr5047830buc.33.1203922988448; Sun, 24 Feb 2008 23:03:08 -0800 (PST) Received: by 10.82.112.18 with HTTP; Sun, 24 Feb 2008 23:03:08 -0800 (PST) Message-ID: <36af4bed0802242303w3bca871cgab3d004a1414faed@mail.gmail.com> Date: Mon, 25 Feb 2008 12:33:08 +0530 From: "Robins Tharakan" To: johnf Subject: Re: postgresql function not accepting null values inselect statement Cc: pgsql-sql@postgresql.org In-Reply-To: <200802220830.56917.jfabiani@yolo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_13232_25872311.1203922988444" References: <001501c8752d$391c8e50$ab55aaf0$@com> <001a01c87534$84eea280$8ecbe780$@com> <47BEA582.A3DD.0030.0@indicator.be> <200802220830.56917.jfabiani@yolo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/179 X-Sequence-Number: 30270 ------=_Part_13232_25872311.1203922988444 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline http://www.postgresql.org/docs/current/static/functions-comparison.html This document states this: Lets assume: A = NULL B = 10 C = NULL SELECT 1 WHERE A = B returns no rows SELECT 1 WHERE A = C returns no rows (even though both A and C are NULL) SELECT 1 WHERE A IS NOT DISTINCT FROM C returns 1 row. essentially the third SQL statement works because it is equivalent to this: SELECT 1 WHERE (A IS NULL AND C IS NULL) OR (A = C) *Robins* On Fri, Feb 22, 2008 at 10:00 PM, johnf wrote: > On Friday 22 February 2008 01:35:47 am Bart Degryse wrote: > > Can you try this... > > > > CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) > > RETURNS SETOF t_functionaries AS > > $BODY$ > > DECLARE > > rec t_functionaries%ROWTYPE; > > BEGIN > > FOR rec IN ( > > SELECT f.functionaryid, f.category, f.description > > FROM functionaries f > > WHERE f.statecd IS NOT DISTINCT FROM p_statecd) > > LOOP > > return next rec; > > END LOOP; > > return; > > END; > > $BODY$ > > LANGUAGE 'plpgsql' VOLATILE; > > > a newbie question. Could you explain why yours works? I don't understand > how > it works if p_statecd = NULL > > > -- > John Fabiani > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings > ------=_Part_13232_25872311.1203922988444 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline http://www.postgresql.org/docs/current/static/functions-comparison.html

This document states this:
Lets assume:
A = NULL
B = 10
C = NULL

SELECT 1 WHERE A = B returns no rows
SELECT 1 WHERE A = C returns no rows (even though both A and C are NULL)
SELECT 1 WHERE A IS NOT DISTINCT FROM C returns 1 row.

essentially the third SQL statement works because it is equivalent to this:

SELECT 1 WHERE (A IS NULL AND C IS NULL) OR (A = C)

Robins


On Fri, Feb 22, 2008 at 10:00 PM, johnf <jfabiani@yolo.com> wrote:
On Friday 22 February 2008 01:35:47 am Bart Degryse wrote:
> Can you try this...
>
> CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer)
>   RETURNS SETOF t_functionaries AS
> $BODY$
> DECLARE
>   rec t_functionaries%ROWTYPE;
> BEGIN
>   FOR rec IN (
>     SELECT f.functionaryid, f.category, f.description
>     FROM functionaries f
>     WHERE f.statecd IS NOT DISTINCT FROM p_statecd)
>   LOOP
>     return next rec;
>   END LOOP;
>   return;
> END;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
>
a newbie question.  Could you explain why yours works?  I don't understand how
it works if p_statecd = NULL


--
John Fabiani

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

------=_Part_13232_25872311.1203922988444-- From Bart.Degryse@indicator.be Mon Feb 25 08:20:26 2008 Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 4592C2E0101 for ; Mon, 25 Feb 2008 04:20:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 89478-07 for ; Mon, 25 Feb 2008 04:20:18 -0400 (AST) X-Greylist: delayed 00:15:01.61156 by SQLgrey-1.7.5 Received: from interscan.indicator.com (mail.indicator.be [193.121.199.3]) by postgresql.org (Postfix) with ESMTP id DB2922E018F for ; Mon, 25 Feb 2008 04:20:20 -0400 (AST) Received: from DOMEXT-MTA by webaccess.indicator.bewith Novell_GroupWise; Mon, 25 Feb 2008 09:05:13 +0100 Message-Id: <47C284BF.A3DD.0030.0@indicator.be> X-Mailer: Novell GroupWise Internet Agent 7.0.1 Date: Mon, 25 Feb 2008 09:05:07 +0100 From: "Bart Degryse" To: "Jyoti Seth" Cc: Subject: Re: postgresql function not accepting null valuesinselect statement References: <001501c8752d$391c8e50$ab55aaf0$@com><001a01c87534$84eea280$8ecb e780$@com> <47BEA582.A3DD.0030.0@indicator.be><200802220830.56917.jfabiani@yolo.com><002401c8776e$17698b80$463ca280$@com> In-Reply-To: <002401c8776e$17698b80$463ca280$@com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=__Part381EB0A3.1__=" X-imss-version: 2.050 X-imss-result: Passed X-imss-approveListMatch: *@indicator.be X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/181 X-Sequence-Number: 30272 --=__Part381EB0A3.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable In the documentation "IS NOT DISTINCT FROM" only appears in version 8.2 The 8.0 and 8.1 documentation only mentions "IS DISTINCT FROM". http://www.postgresql.org/docs/8.2/static/functions-comparisons.html=20 http://www.postgresql.org/docs/8.1/static/functions-comparisons.html=20 http://www.postgresql.org/docs/8.0/static/functions-comparisons.html=20 I haven't tried it, but probably replacing WHERE f.statecd IS NOT DISTINCT FROM p_statecd) with WHERE not(f.statecd IS DISTINCT FROM p_statecd)) will do the same. =20 >>> "Jyoti Seth" 2008-02-25 6:20 >>> I have tried this, but it is showing following error: ERROR: syntax error at or near "DISTINCT" SQL state: 42601 Thanks, Jyoti -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org= ]=20 On Behalf Of johnf Sent: Friday, February 22, 2008 10:01 PM To: pgsql-sql@postgresql.org=20 Subject: Re: [SQL] postgresql function not accepting null values inselect statement On Friday 22 February 2008 01:35:47 am Bart Degryse wrote: > Can you try this... > > CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) > RETURNS SETOF t_functionaries AS > $BODY$ > DECLARE > rec t_functionaries%ROWTYPE; > BEGIN > FOR rec IN ( > SELECT f.functionaryid, f.category, f.description > FROM functionaries f > WHERE f.statecd IS NOT DISTINCT FROM p_statecd) > LOOP > return next rec; > END LOOP; > return; > END; > $BODY$ > LANGUAGE 'plpgsql' VOLATILE; > a newbie question. Could you explain why yours works? I don't understand how=20 it works if p_statecd =3D NULL --=20 John Fabiani ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org ( http://archives.postgresql.= org/ ) --=__Part381EB0A3.1__= Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Description: HTML
In the documentation "IS NOT DISTINCT FROM" only appears in version = 8.2
The 8.0 and 8.1 documentation only mentions "IS DISTINCT FROM".
I haven't tried it, but probably replacing
     WHERE f.statecd IS NOT DISTINCT FROM = p_statecd)
with
     WHERE not(f.statecd IS DISTINCT FROM = p_statecd))
will do the same.
 

>>> "Jyoti Seth" <jyotiseth2001@gmail.com> = 2008-02-25 6:20 >>>
I have tried this, but it is showing = following error:
ERROR: syntax error at or near "DISTINCT"
SQL = state: 42601

Thanks,
Jyoti


-----Original Message-----<= BR>From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.= org]
On Behalf Of johnf
Sent: Friday, February 22, 2008 10:01 = PM
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] postgresql = function not accepting null values inselect
statement

On Friday = 22 February 2008 01:35:47 am Bart Degryse wrote:
> Can you try = this...
>
> CREATE OR REPLACE FUNCTION getfunctionaries(p_state= cd integer)
>   RETURNS SETOF t_functionaries AS
> = $BODY$
> DECLARE
>   rec t_functionaries%ROWTYPE;
= > BEGIN
>   FOR rec IN (
>    = SELECT f.functionaryid, f.category, f.description
>   = ;  FROM functionaries f
>     WHERE = f.statecd IS NOT DISTINCT FROM p_statecd)
>   LOOP
>&= nbsp;    return next rec;
>   END LOOP;
&= gt;   return;
> END;
> $BODY$
> LANGUAGE = 'plpgsql' VOLATILE;
>
a newbie question.  Could you explain = why yours works?  I don't understand
how
it works if p_statecd = =3D NULL


--
John Fabiani

---------------------------(= end of broadcast)---------------------------
TIP 5: don't forget to = increase your free space map settings


--------------------------= -(end of broadcast)---------------------------
TIP 4: Have you searched = our list archives?

        &= nbsp;      http://archives.postgresql.org
--=__Part381EB0A3.1__=--