Re: ERROR: AlterTableAddConstraint: - Mailing list pgsql-general

From Tom Lane
Subject Re: ERROR: AlterTableAddConstraint:
Date
Msg-id 13804.997313174@sss.pgh.pa.us
Whole thread Raw
In response to ERROR: AlterTableAddConstraint:  (missive@frontiernet.net (Lee Harr))
List pgsql-general
missive@frontiernet.net (Lee Harr) writes:
> The table should look like:

> CREATE TABLE AA (t timestamp default current_timestamp
>   CHECK (t = current_timestamp));

I don't think this is possible or sensible.  A constraint is an
assertion, it should be valid whenever you check it (with the
single exception that DEFERRED constraints don't have to hold
intra-transaction).

I think what you really want is an ON INSERT OR UPDATE trigger that sets
the value of t to current_timestamp (regardless of what the user tried
to put in the column).  You don't need a constraint, and you don't even
need a default --- the default just represents a wasted function call,
if you do it this way.

            regards, tom lane

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: ERROR: AlterTableAddConstraint:
Next
From: newsreader@mediaone.net
Date:
Subject: createdb confusion