Re: ARRAY() returning NULL instead of ARRAY[] resp. {}

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Markus Bertheau ☭ <twanger(at)bluetwanger(dot)de>
Cc: Joe Conway <mail(at)joeconway(dot)com>, pgsql-sql(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ARRAY() returning NULL instead of ARRAY[] resp. {}
Date: 2005-06-06 14:44:49
Message-ID: 25974.1118069089@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches pgsql-sql

Markus Bertheau =?UTF-8?Q?=E2=98=AD?= <twanger(at)bluetwanger(dot)de> writes:
> By analogy, array_upper('{}'::TEXT[], 1) should return 0 instead of
> NULL.

No, that doesn't follow ... we've traditionally considered '{}' to
denote a zero-dimensional array. A 1-D array of no elements is
'[1:0]={}', just as Joe shows ... or at least it would be except
for an overenthusiastic error check:

regression=# select '[1:0]={}' :: int[];
ERROR: upper bound cannot be less than lower bound

I think this should be a legal boundary case. In general, it should be
possible to form zero-size arrays of any number of dimensions.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jaime Casanova 2005-06-06 14:44:57 Re: thw rewriter and default values, again
Previous Message Tom Lane 2005-06-06 14:18:43 Re: Quick-and-dirty compression for WAL backup blocks

Browse pgsql-patches by date

  From Date Subject
Next Message Markus Bertheau ☭ 2005-06-06 14:54:59 Re: [SQL] ARRAY() returning NULL instead of ARRAY[] resp. {}
Previous Message Markus Bertheau ☭ 2005-06-06 14:17:24 Re: ARRAY() returning NULL instead of ARRAY[] resp. {}

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2005-06-06 14:45:02 Re: What is faster?
Previous Message Tom Lane 2005-06-06 14:31:15 Re: how to store more than 3 MB of character data in Postgres Varchar field