Empty arrays with ARRAY[] - Mailing list pgsql-general

From Brendan Jurd
Subject Empty arrays with ARRAY[]
Date
Msg-id 37ed240d0711250851k6f917ce1v1c014393f8777c94@mail.gmail.com
Whole thread Raw
Responses Re: Empty arrays with ARRAY[]  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
Hi all,

I noticed in the 8.3 release notes that ARRAY(SELECT ...) now returns
an empty array if there are no rows returned by the subquery.

Until reading this, I didn't even realise that empty arrays were
possible, since ARRAY[] causes a syntax error.  I played around with
the array input syntax and found that you can create an empty array
with literal input (e.g., with '{}'::int[]), but it's not possible
with ARRAY[].  Apparently the array constructor syntax requires

"a left square bracket [, one or more expressions (separated by
commas) for the array element values, and finally a right square
bracket ]" [1].

My question is, if it's possible to create an empty array, why is the
array constructor designed to only construct arrays with at least one
element?

I'm thinking it's because the constructor needs to decide what type to
make the array.  Is that correct, and if so, would the following TODO
item make ARRAY[] possible?

"Delay resolution of array expression's data type so assignment
coercion can be performed on empty array expressions"

Regards,
BJ

[1] http://www.postgresql.org/docs/8.3/static/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS

pgsql-general by date:

Previous
From: Никоноров Григорий
Date:
Subject: Error while compiling PostgreSQL with Java
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Empty arrays with ARRAY[]