Re: forcing a literal value in a column - Mailing list pgsql-general

From Stephan Szabo
Subject Re: forcing a literal value in a column
Date
Msg-id 20030513072228.A26288-100000@megazone23.bigpanda.com
Whole thread Raw
In response to forcing a literal value in a column  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Responses Re: forcing a literal value in a column
List pgsql-general
On Tue, 13 May 2003, Karsten Hilbert wrote:

> in my audit trail tables I want two columns to _always_ be
> CURRENT_USER/CURRENT_TIMESTAMP.

I'm guessing you mean that you want the two columns to always be the
user/time of the row's last modification, not always the current user and
current time (of who/when a select is done).

> I am currently doing this:
>  ...
>  modified_by name not null default CURRENT_USER check(modified_by=CURRENT_USER),
>  ...
> (respective for CURRENT_TIMESTAMP)
>
> I know this can also be achieved with a trigger on insert/update.
> However, I'd like to know what is the "PostgreSQL way" of
> doing this ? Do I achieve what I want with my above solution ?

Assuming you want an automatically modified field, probably not.  As you
noted, defaults aren't automatically propogated to columns on update.
Triggers are probably the best way to do it.


pgsql-general by date:

Previous
From: Network Administrator
Date:
Subject: Re: Creating functions and triggers
Next
From: Tom Lane
Date:
Subject: Re: forcing a literal value in a column