Re: Array_append does not work with Array variables in PL/pgSQL? - Mailing list pgsql-sql

From Joe Conway
Subject Re: Array_append does not work with Array variables in PL/pgSQL?
Date
Msg-id 406C8B6D.2040603@joeconway.com
Whole thread Raw
In response to Array_append does not work with Array variables in PL/pgSQL?  (Josh Berkus <josh@agliodbs.com>)
Responses Re: Array_append does not work with Array variables in PL/pgSQL?  (Josh Berkus <josh@agliodbs.com>)
List pgsql-sql
Josh Berkus wrote:
>  v_vals TEXT[];
>  n_vals TEXT[];

try:  v_vals TEXT[] := ''{}'';  n_vals TEXT[] := ''{}'';

You have to initialize the array to something non-null, even if that be 
an empty array (note that there is a difference). When trying to append 
an element to a NULL valued array, you wind up with a NULL result. It is 
similar to:

regression=# select (NULL || 'abc') is null; ?column?
---------- t
(1 row)

Joe


pgsql-sql by date:

Previous
From: Josh Berkus
Date:
Subject: Array_append does not work with Array variables in PL/pgSQL?
Next
From: Josh Berkus
Date:
Subject: Re: Array_append does not work with Array variables in PL/pgSQL?