Re: [GENERAL] Empty arrays with ARRAY[]

Поиск
Список
Период
Сортировка
От Brendan Jurd
Тема Re: [GENERAL] Empty arrays with ARRAY[]
Дата
Msg-id 37ed240d0711300114w5dfa408m1bfa2cc408cc98e1@mail.gmail.com
обсуждение исходный текст
Ответы Re: [GENERAL] Empty arrays with ARRAY[]  (Gregory Stark <stark@enterprisedb.com>)
Re: [GENERAL] Empty arrays with ARRAY[]  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-patches
As discussed on -hackers, this patch allows the construction of an
empty array if an explicit cast to an array type is given (as in,
ARRAY[]::int[]).

postgres=# select array[]::int[];
 array
-------
 {}

postgres=# select array[];
ERROR:  no target type for empty array
HINT:  Empty arrays must be explictly cast to the desired array type,
e.g. ARRAY[]::int[]

A few notes on the implementation:

 * The syntax now allows an ARRAY constructor with an empty expression
list (array_expr_list may be empty).

 * I've added a new parsenode for arrays, A_ArrayExpr (previously the
parser would create ArrayExpr primnodes).

 * transformArrayExpr() now takes two extra arguments, a type oid and
a typmod.  When transforming a typecast which casts an A_ArrayExpr to
an array type, transformExpr passes these type details down to
transformArrayExpr, and skips the typecast.

 * transformArrayExpr() behaves slightly differently when passed type
information.  The overall type of the array is set to the given type,
and all elements are explictly coerced to the equivalent element type.
 If it was not passed a type, then the behaviour is as previous; the
function looks for a common type among the elements, and coerces them
to that type.  The overall type of the array is derived from the
common element type.

The patch is very invasive (at least compared to any of my previous
patches), but so far I haven't managed to find any broken behaviour.
All regression tests pass, and the regression tests for arrays seem to
be quite comprehensive.  I did add a couple of new tests for the empty
array behaviours, but the rest I've left alone.

I look forward to your comments -- although given the length of the
8.4 patch review queue, that will probably be an exercise in extreme
patience!

Major thanks go out to Tom for all his guidance on -hackers while I
developed the patch.

Regards,
BJ

Вложения

В списке pgsql-patches по дате отправления:

Предыдущее
От: Jorgen Austvik - Sun Norway
Дата:
Сообщение: Re: pg_regress: paths in largeobject test
Следующее
От: Simon Riggs
Дата:
Сообщение: Re: [DOCS] Partition: use triggers instead of rules