Re: Declaring empty, non-NULL array in plpgsql

From: Joe Conway <mail(at)joeconway(dot)com>
To: CSN <cool_screen_name90001(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Declaring empty, non-NULL array in plpgsql
Date: 2003-11-24 05:45:10
Message-ID: 3FC19AE6.1050007@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

CSN wrote:
> This avoids the NULL problem - is there a better way?
>
> aCats varchar[] = array[''''];

aCats varchar[] = ''{}'';

This gives you a truly empty array that can later become single or
multidimensional.

e.g.

regression=# select '{}'::int[] || 1;
?column?
----------
{1}
(1 row)

regression=# select '{}'::int[] || array[1,2];
?column?
----------
{1,2}
(1 row)

regression=# select '{}'::int[] || array[[1,2],[3,4]];
?column?
---------------
{{1,2},{3,4}}
(1 row)

HTH,

Joe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message igor 2003-11-24 08:59:02 Re: why ORDER BY works wrong in pg7.3.4?
Previous Message CSN 2003-11-24 05:26:25 Re: Declaring empty, non-NULL array in plpgsql