on update of table set timestamp

on update of table set timestamp

am 22.06.2010 16:33:09 von Lance

This is a multi-part message in MIME format.

------_=_NextPart_001_01CB1218.47F8301A
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

PostgreSQL 8.4

I want to add a timestamp column to some of my important table such that
whenever an SQL "update" command is executed on the table the
"updated_timestamp" timestamp column would be set with "now()". Is
there a way to do this? I know I could go through and change my SQL all
over the place to update a column "updated_timestamp" with "now()" but
it would be faster if there was some way to set a constraint and/or
default value on the field. Is this possible. I don't really want to
do store procedures.=20

=20

Thanks,

=20

Lance Campbell

Software Architect/DBA/Project Manager

Web Services at Public Affairs

217-333-0382

=20


------_=_NextPart_001_01CB1218.47F8301A
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40">


charset=3Dus-ascii">









PostgreSQL 8.4



I want to add a timestamp column to some of my =
important table
such that whenever an SQL “update” command is executed on =
the table
the “updated_timestamp” timestamp column would be set with =
“now()”. 
Is there a way to do this?  I know I could go through and change my =
SQL
all over the place to update a column “updated_timestamp” =
with “now()”
but it would be faster if there was some way to set a constraint and/or =
default
value on the field.  Is this possible.  I don’t really =
want to
do store procedures.



 



Thanks,



 



Lance Campbell



Software Architect/DBA/Project =
Manager



Web Services at Public Affairs



217-333-0382



 









------_=_NextPart_001_01CB1218.47F8301A--

Re: on update of table set timestamp

am 22.06.2010 16:55:16 von Kevin Grittner

"Campbell, Lance" wrote:

> I want to add a timestamp column to some of my important table
> such that whenever an SQL "update" command is executed on the
> table the "updated_timestamp" timestamp column would be set with
> "now()".

I would write one function which I would bind as a BEFORE UPDATE
trigger to all the tables with the updated_timestamp column. You
don't need to write a separate function for each table.

-Kevin

--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin