Обсуждение: How do we use classes as types?

Поиск
Список
Период
Сортировка

How do we use classes as types?

От
"Oliver Elphick"
Дата:
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.Elphick@lfix.co.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



Re: How do we use classes as types?

От
Tom Lane
Дата:
"Oliver Elphick" <olly@lfix.co.uk> writes:
> It is possible to use a class as an attribute of another class:

Apparently that used to work back in Berkeley Postgres (pre-SQL) days.
I do not think it works anymore...

            regards, tom lane