Re: Populating array of composite datatype - Mailing list pgsql-general

From David Johnston
Subject Re: Populating array of composite datatype
Date
Msg-id 1375886733223-5766656.post@n5.nabble.com
Whole thread Raw
In response to Populating array of composite datatype  (Sameer Thakur <samthakur74@gmail.com>)
Responses Re: Populating array of composite datatype  (John McKown <john.archie.mckown@gmail.com>)
List 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 by date:

Previous
From: Igor Neyman
Date:
Subject: Re: Self referencing composite datatype
Next
From: David Johnston
Date:
Subject: Re: Self referencing composite datatype