Empty arrays with ARRAY[]

Поиск
Список
Период
Сортировка
От Brendan Jurd
Тема Empty arrays with ARRAY[]
Дата
Msg-id 37ed240d0711250851k6f917ce1v1c014393f8777c94@mail.gmail.com
обсуждение исходный текст
Ответы Re: Empty arrays with ARRAY[]
Список 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 по дате отправления:

Предыдущее
От: Никоноров Григорий
Дата:
Сообщение: Error while compiling PostgreSQL with Java
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Empty arrays with ARRAY[]