Re: inheritance and audit columns - Mailing list pgsql-novice

From Oliver Elphick
Subject Re: inheritance and audit columns
Date
Msg-id 1011089933.9010.28.camel@linda
Whole thread Raw
In response to inheritance and audit columns  ("Jules Alberts" <julesa@arbodienst-limburg.nl>)
Responses Re: inheritance and audit columns
List pgsql-novice
On Mon, 2002-01-14 at 14:20, Jules Alberts wrote:
...
> what may cause a problem though is that i want to do multiple
> inheritance, something like:
>
> /** start of code **/
> create table dummy (
>   dummy_id serial primary_key,
>   dummy_name varchar(100)
> ) inherits (foo, bar);
> /** end of code **/
>
> i have two questions about this statement:
>
> 1. the manual says that multiple inheritance is possible, but doesn't
> give an example. is the syntax "inherits (foo, bar)" correct?
>
> 2. both foo and bar have (inherited) columns called mut_user and
> mut_timestamp. can i expect a conflict when creating dummy?
>
> i couldn't find the answers neither in the online help nor in Bruces
> book, also online (maybe i didn't search good enough), so TIA for any
> pointers!

Well, the simple method is to try it!  (Which would show you that
"primary_key" is wrong; it should be "primary key".):


junk=# create table dummy (
junk(#   dummy_id serial primary key,
junk(#   dummy_name varchar(100)
junk(# ) inherits (foo, bar);
NOTICE:  CREATE TABLE will create implicit sequence 'dummy_dummy_id_seq'
for SERIAL column 'dummy.dummy_id'
NOTICE:  CREATE TABLE/PRIMARY KEY will create implicit index
'dummy_pkey' for table 'dummy'
NOTICE:  CREATE TABLE: merging multiple inherited definitions of
attribute "mut_user"
NOTICE:  CREATE TABLE: merging multiple inherited definitions of
attribute "mut_timestamp"
CREATE

Duplicate multiply inherited columns will be merged if they are of the
same type.  It is an error to have them of the same name but different
types:

junk=# create table try (mut_user char(10));
CREATE
junk=# create table foobar (junk serial primary key) inherits
(audit_cols, try);
NOTICE:  CREATE TABLE will create implicit sequence 'foobar_junk_seq'
for SERIAL column 'foobar.junk'
NOTICE:  CREATE TABLE/PRIMARY KEY will create implicit index
'foobar_pkey' for table 'foobar'
NOTICE:  CREATE TABLE: merging multiple inherited definitions of
attribute "mut_user"
ERROR:  CREATE TABLE: inherited attribute "mut_user" type conflict
(varchar and bpchar)

There are problems with inheritance with regard to inheritance of primry
keys and use of parent tables in foreign key references; see in the todo
details directory.
--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C

     "For I know that my redeemer liveth, and that he shall
      stand at the latter day upon the earth"
                                       Job 19:25

Attachment

pgsql-novice by date:

Previous
From: Andreas Fitzner
Date:
Subject: Re: length(columnname), solved
Next
From: "Jules Alberts"
Date:
Subject: Re: inheritance and audit columns