Re: SELECT table_type FROM table;

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "A(dot)M(dot)" <agentm(at)themactionfaction(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT table_type FROM table;
Date: 2006-05-26 15:26:02
Message-ID: 26160.1148657162@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"A.M." <agentm(at)themactionfaction(dot)com> writes:
> agentm=# select testo from testo;
> testo
> -----------
> (1,hello)
> (2,text)
> (2 rows)

> Obviously, this is intentional behavior but where is it documented?

Well, it's mentioned in passing in section 32.4.2 "SQL Functions on
Composite Types",
http://www.postgresql.org/docs/8.1/static/xfunc-sql.html#AEN31648
where it says "The table row can alternatively be referenced using just
the table name". Personally I prefer the syntax "table.*"; the syntax
without * is a holdover from PostQUEL IIRC.

> agentm=# select *::nice from testo;
> ERROR: syntax error at or near "::" at character 9

The syntactically right thing would be

regression=# select testo::nice from testo;
ERROR: cannot cast type testo to nice
or
regression=# select (testo.*)::nice from testo;
ERROR: cannot cast type testo to nice

We don't have any automatic support for casts from one composite type to
another, but you can add your own:

regression=# create function nice(testo) returns nice language sql as $$
regression$# select $1.* $$ strict immutable;
CREATE FUNCTION
regression=# create cast(testo as nice) with function nice(testo);
CREATE CAST
regression=# select (testo.*)::nice from testo;
testo
-----------
(1,hello)
(2,text)
(2 rows)

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Florian G. Pflug 2006-05-26 15:38:14 Re: RES: LDAP authentication
Previous Message Scott Marlowe 2006-05-26 15:01:43 Re: delete is extremely slow