Re: ERROR: AlterTableAddConstraint:

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: missive(at)hotmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ERROR: AlterTableAddConstraint:
Date: 2001-08-08 23:26:14
Message-ID: 13804.997313174@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

missive(at)frontiernet(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message newsreader 2001-08-09 00:16:35 createdb confusion
Previous Message Stephan Szabo 2001-08-08 23:21:11 Re: ERROR: AlterTableAddConstraint: