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

inheritance and audit columns

From: "Jules Alberts" <julesa(at)arbodienst-limburg(dot)nl>
To: pgsql-novice(at)postgresql(dot)org
Subject: inheritance and audit columns
Date: 2002-01-14 14:20:06
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
hi everyone,

i have several questions. first, i want to have audit columns in every 
table of my database. these should hold information about who has last 
edited a column on which time/date. to avoid a lot of repetition i 
would like to use inheritance. something like this:

/** start of code **/
create table audit_cols (
  mut_user varchar(100) not null default current_user,
  mut_timestamp timestamp not null default CURRENT_TIMESTAMP

create table foo (
  foo_id serial primary_key,
  foo_name varchar(100)
) inherits (audit_cols);

create table bar (
  bar_id serial primary_key,
  bar_name varchar(100)
) inherits (audit_cols);
/** end of code **/

i have to think of some functions that will automatically fill the 
audit_cols columns, but that should not be a big problem, the idea is 
that i can have every table inheriting from audit_cols.

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 

Jules Alberts.


pgsql-novice by date

Next:From: David AnthonyDate: 2002-01-14 14:25:12
Previous:From: ChristopherDate: 2002-01-14 12:31:49
Subject: Re: length(columnname), solved

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