Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I created a user-defined type in a PostgreSQL 9.2 database and am trying in the SELECT statement to get only an attribute of the UDT. However, I don't seem to get my code to work.

Creation of type and table:

CREATE TYPE  ttp AS (f1 int, f2 int);
CREATE TABLE tbl (ctyp ttp);

The SELECT statement:

-- does not work
SELECT ctyp.f1 FROM tbl
SELECT ctyp(f1) FROM testtable

Both times I get an error. Is it possible to access a single attribute defined in a UDT in a SELECT?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Use:

SELECT (ctyp).f1 FROM tbl;

The parentheses are necessary to disambiguate tables from composite types as detailed in the manual on composite types.

share|improve this answer
    
Thanks! The difference is very subtle. Btw, I thought it might be somewhere written in the manual, but I really couldn't find it. Thanks again! –  navige Mar 20 '13 at 22:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.