Re: Populating array of composite datatype

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Populating array of composite datatype
Дата
Msg-id 1375886733223-5766656.post@n5.nabble.com
обсуждение исходный текст
Ответ на Populating array of composite datatype  (Sameer Thakur <samthakur74@gmail.com>)
Ответы Re: Populating array of composite datatype  (John McKown <john.archie.mckown@gmail.com>)
Список pgsql-general
Sameer Thakur wrote
> insert into test values (ARRAY[abc(1,2)]); but got error

When you use a function form of casting like this you are basically
short-circuiting the type conversion mechanisms built into PostgreSQL by
directly calling the conversion function instead of actually telling the
system to perform a cast where the input is of one type and the output is of
another.  While direct function invocation will work in some instances it is
better not to rely on it.  If you really do mean to convert from one type to
another you should - almost always - use either:

the SQL standard

CAST('val' AS type)

or the PostgreSQL short-hand

'val'::type

[It seriously sucks that the standard syntax for casting is so verbose that
it is almost unusable unless you must - immediately - have cross-database
compatibility and thus can withstand the pain using it inflicts.]

There are a bunch more comments, rules, and warnings on this topic somewhere
in the documentation if you are really curious but, really, just use the
explicit casting mechanism provided by the database instead of calling the
casting functions directly.

Note I am not positive that abc(1,2) is truly an instance of this behavior
but I'm guessing you tried doing this because similar syntax has worked for
you before due to the behavior I've referenced above.

David J.




--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Populating-array-of-composite-datatype-tp5766628p5766656.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


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

Предыдущее
От: Igor Neyman
Дата:
Сообщение: Re: Self referencing composite datatype
Следующее
От: David Johnston
Дата:
Сообщение: Re: Self referencing composite datatype