Re: ERROR: AlterTableAddConstraint:

From: missive(at)frontiernet(dot)net (Lee Harr)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: ERROR: AlterTableAddConstraint:
Date: 2001-08-09 22:54:15
Message-ID: 9kv4am$3s86$1@node21.cwnet.roc.gblx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 8 Aug 2001 23:32:19 +0000 (UTC), Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> 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

Ok, thank you.

I misunderstood the whole CHECK thing. I thought it was actually creating
a trigger for you, kind of like SERIAL or PRIMARY KEY creates extra stuff
automatically.

Guess I get to learn how to make a trigger :)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brian C. Doyle 2001-08-09 23:11:50 Re: UpGrading to 7.1.2
Previous Message Peter Eisentraut 2001-08-09 22:42:33 Re: FATAL 1