Search Postgresql Archives

Empty arrays with ARRAY[]

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

 



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

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

[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