Search Postgresql Archives

Re: invalid input syntax for integer: "NULL"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux