Re: invalid input syntax for integer: "NULL"

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(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:25:20
Message-ID: 20070220152044.M31141@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 20 Feb 2007, 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.
> The following code is for reproducing:
>
> CREATE TABLE test(
> bh INT8
> );
>
> CREATE OR REPLACE FUNCTION testinsertion(intornull bigint) RETURNS text AS
> $$
> DECLARE
> BEGIN
> RETURN 'INSERT INTO test (bh) VALUES ('||COALESCE(intornull, 'NULL')||')';

I think you'd need something like
COALESCE(CAST(intornull AS TEXT), 'NULL')
in order to make that work. You want the output to effectively be a string
which contains the int to be concatenated with the other strings or the
string 'NULL' to be concatentated with the other strings.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tomi N/A 2007-02-20 23:30:30 can't stop the postmaster?
Previous Message Ron Mayer 2007-02-20 23:19:06 Re: Priorities for users or queries?