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.