How do we use classes as types?

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: How do we use classes as types?
Date: 2000-12-30 20:32:19
Message-ID: 200012302032.eBUKWKH19890@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

It is possible to use a class as an attribute of another class:

bray=# create table junk (id serial PRIMARY KEY, dt DATE NOT NULL);
NOTICE: CREATE TABLE will create implicit sequence 'junk_id_seq' for SERIAL
column 'junk.id'
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'junk_pkey' for
table 'junk'
CREATE

bray=# create table junk1 (j junk, descrip text);
CREATE

But I cannot find any documentation on how to insert a row into junk1.
Nothing I have tried works:

bray=# insert into junk1 values (null, current_date, 'this is text');
ERROR: Attribute 'j' is of type 'junk' but expression is of type 'unknown'
You will need to rewrite or cast the expression
bray=# insert into junk1 values ((null, current_date), 'this is text');
ERROR: parser: parse error at or near ","
bray=# insert into junk1 values ((null, current_date)::junk, 'this is text');
ERROR: parser: parse error at or near "::"
bray=# insert into junk1 (j.dt, descrip) values ( current_date, 'this is
text');
ERROR: parser: parse error at or near "."

etc...

Does anyone know how to get rows into such a table?

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Give to him that asketh thee, and from him that would
borrow of thee turn not away."
Matthew 5:42

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Franck Martin 2000-12-30 21:09:01 new geoobj type in PG.
Previous Message Adam Lang 2000-12-30 18:41:51 Re: MySQL and PostgreSQL speed compare