Re: update ARRAY of COMPOSITE TYPE of text

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: update ARRAY of COMPOSITE TYPE of text
Дата
Msg-id 15573.1369319295@sss.pgh.pa.us
обсуждение исходный текст
Ответ на update ARRAY of COMPOSITE TYPE of text  (Wojciech Skaba <wojciech.skaba@teleadreson.pl>)
Список pgsql-general
Wojciech Skaba <wojciech.skaba@teleadreson.pl> writes:
> UPDATE directory SET faxes = ARRAY[ROW('11', '2222222', '333'), ROW('44', '555', '666')] WHERE id = 1;
> has failed: (You will need to rewrite or cast the expression) with arrow pointing to ARRAY.

> Does anybody know how to overcome it?

Just like it says, cast the expression:

UPDATE directory SET faxes = ARRAY[ROW('11', '2222222', '333'), ROW('44', '555', '666')]::telephone[] WHERE id = 1;

or if it's more convenient for your app, do it like this:

UPDATE directory SET faxes = ARRAY[ROW('11', '2222222', '333')::telephone, ROW('44', '555', '666')::telephone] WHERE id
=1; 

I don't recall at the moment why we allow implicit casting from an
anonymous "record" type to a named composite type but not from record[]
to an array of named composite.  There might be a good reason for it,
or just a lack of round tuits.

            regards, tom lane


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

Предыдущее
От: Keith Fiske
Дата:
Сообщение: Foreign Key violated
Следующее
От: Thom Brown
Дата:
Сообщение: Re: Foreign Key violated