Skip site navigation (1) Skip section navigation (2)

Re: CREATE TABLE with a column of type {table name}

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Ang Chin Han <angch(at)bytecraft(dot)com(dot)my>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: CREATE TABLE with a column of type {table name}
Date: 2003-07-31 10:56:33
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
On Thu, 31 Jul 2003, Ang Chin Han wrote:

> In Postgresql 7.3, a datatype can be int, text, etc, and also
> pseudo-types like RECORD, any, etc.
> These pseudo types are mainly used in CREATE FUNCTIONs, but what if it's
> used in a CREATE TABLE, esp. when the name of another table is used as a
> datatype?
> -- Hmmm... What if pseudo-types in CREATE TABLEs?
> CREATE TABLE bar(myfoo foo, c int);
> -- The only way I can think of to insert values into the table bar:
> SELECT INTO bar SELECT get_foo1(), 1;

You can write casts as well presumably to allow other inputs.

> -- How to retrieve data from bar?
> SELECT * FROM bar;
> ERROR:  Cannot display a value of type RECORD
> SELECT myfoo.a FROM bar;
> ERROR:  Attribute "myfoo.a" not found

However the syntax
 select a(myfoo),b(myfoo) from bar
should work.

In response to


pgsql-general by date

Next:From: Tambet MatiisenDate: 2003-07-31 11:42:33
Subject: COPY and domains
Previous:From: Jonathan MezachDate: 2003-07-31 10:46:08
Subject: Re: Updating from update trigger

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group