Re: Updating column on row update

From: Thom Brown <thombrown(at)gmail(dot)com>
To: Aaron Burnett <aburnett(at)bzzagent(dot)com>
Cc: PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Updating column on row update
Date: 2009-11-22 20:09:04
Message-ID: bddc86150911221209n6ffc5260ye007187522277a77@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

2009/11/22 Aaron Burnett <aburnett(at)bzzagent(dot)com>

>
> this is how I do it if this helps:
>
> column_name timestamp without time zone NOT NULL DEFAULT
> ('now'::text)::timestamp(6) without time zone
>
> Hi Aaron. Thanks for the reply, but that would only insert the current
date upon insertion into the table, not when the row is updated.

For example

CREATE TABLE timetest(
id SERIAL NOT NULL,
stuff text,
stamp timestamp NOT NULL DEFAULT now()
);

INSERT INTO timetest (stuff) VALUES ('meow');

The table would contain:

id | stuff | stamp
----+-------+----------------------------
1 | meow | 2009-11-22 20:04:51.261739

But then I'd execute:

UPDATE timetest SET stuff = 'bark' WHERE id = 1;

id | stuff | stamp
----+-------+----------------------------
1 | bark | 2009-11-22 20:04:51.261739

You can see the time hasn't changed. But I'd want that stamp column to
update to the current time without referring to that column in the update
statement.

Thanks

Thom

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2009-11-22 20:15:06 Re: Updating column on row update
Previous Message Aaron Burnett 2009-11-22 19:57:48 Re: Updating column on row update

Browse pgsql-hackers by date

  From Date Subject
Next Message Scott Marlowe 2009-11-22 20:15:06 Re: Updating column on row update
Previous Message Stephan Szabo 2009-11-22 20:02:08 Re: Partitioning option for COPY