Thread: ask for parts of a user defined types

ask for parts of a user defined types

From
Kjetil Haaland
Date:
Hi

I am wondering if it is possible to select values from user defined types.
That is, if a new type is defined like for example the Complex type in the
documentation, is it then possible to select just one of the double values
that this type keeps? (this is not a good example, but in other types with
other values this might be interesting) In c structures this is possible
using the dot notation or ->. Is this possible in some way in PostgreSQL too?

thanks
Kjetil

Re: ask for parts of a user defined types

From
Tom Lane
Date:
Kjetil Haaland <kjetil.haaland@student.uib.no> writes:
> I am wondering if it is possible to select values from user defined types.
> That is, if a new type is defined like for example the Complex type in the
> documentation, is it then possible to select just one of the double values
> that this type keeps?

Yes, but there are some syntactic issues that get in the way because
"foo.bar" is a table name and field name according to the SQL standard.

In PG >= 8.0 you can select a field from something that isn't a table
by parenthesizing; see the examples here:
    http://www.postgresql.org/docs/8.0/static/rowtypes.html

In earlier versions you frequently have to fall back on the old PostQUEL
functional syntax: write bar(foo) where you mean foo.bar.

            regards, tom lane