From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net> |
Cc: | PostgreSQL General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: forcing a literal value in a column |
Date: | 2003-05-13 14:25:48 |
Message-ID: | 20030513072228.A26288-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-05-13 14:34:27 | Re: forcing a literal value in a column |
Previous Message | Network Administrator | 2003-05-13 14:06:36 | Re: Creating functions and triggers |