From: | "Karl O(dot) Pinc" <kop(at)meme(dot)com> |
---|---|
To: | Yonatan Ben-Nes <yonatan(at)epoch(dot)co(dot)il> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: invalid input syntax for integer: "NULL" |
Date: | 2007-02-20 23:14:34 |
Message-ID: | 1172013274l.19116l.3l@mofo |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 02/20/2007 03:45:55 PM, Yonatan Ben-Nes wrote:
> Hi everyone,
>
> I'm trying to write a PL/pgSQL function which execute an insert, I
> encounter
> a problem when I try to insert NULL value into an integer field.
> RETURN 'INSERT INTO test (bh) VALUES ('||COALESCE(intornull,
> 'NULL')||')';
> And if I try to change the COALESCE second value at the function to
> NULL
> (instead of 'NULL') it works if a value is being passed to the
> integer field
> but doesn't work if a NULL Is passed:
NULL, without the quotes, is the proper way to write
NULL as a literal value. When you put quotes around it it's a
string. So that's why you get a type exception.
COALESCE chooses the first value that's not NULL. So if you
pass it NULL you may as well not supply the second argument.
You probably want a plpgsql IF statement or a CASE expression.
Karl <kop(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein
From | Date | Subject | |
---|---|---|---|
Next Message | Ron Mayer | 2007-02-20 23:19:06 | Re: Priorities for users or queries? |
Previous Message | Rhys Stewart | 2007-02-20 22:15:38 | Re: Installing support for python on windows |