From: Christophe Labouisse <labouiss@club-internet.fr>
To: pgsql-sql@postgreSQL.org
Subject: Triggers, plpgsql, etc.
Date: 15 Jan 1999 13:10:58 +0100
Message-ID: <m3hftsg2i5.fsf@gabuzo.meunet> (raw)
I want to have a « date of the last update » field in a table. So I
create a table with datetime field (liens_maj) and a default value to
'now'.
As shown below it works fine.
lumiere=> insert into liens (liens_nom,liens_url) values ('Ga','GAbuzo');
INSERT 1009600 1
lumiere=> select * from liens;
liens_id|liens_nom|liens_url|liens_commentaire|liens_maj
--------+---------+---------+-----------------+----------------------------
1|Ga |GAbuzo | |Thu Jan 14 13:29:35 1999 CET
(1 row)
To update automatically this field when the row is updated I thought
of a trigger calling a plpgsql function :
create trigger liens_maj_trig after update
on liens for each row execute procedure liens_maj_fun();
create function liens_maj_fun () returns opaque as '
begin
update liens set liens_maj=''now'' where liens_id=old.liens_id;
return new;
end;
' language 'plpgsql';
When I try to update a record I get the following error :
lumiere=> update liens set liens_nom='zzz' where liens_id=1;
ERROR: There is no operator '=$' for types 'int4' and 'int4'
You will either have to retype this query using an explicit cast,
or you will have to define the operator using CREATE OPERATOR
Any idea ?
Christophe Labouisse : Cinéma, typographie, Unix
labouiss@club-internet.fr http://gabuzo.home.ml.org/
Le cinéma en Lumière : http://www.lumiere.org/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: labouiss@club-internet.fr
Subject: Re: Triggers, plpgsql, etc.
In-Reply-To: <m3hftsg2i5.fsf@gabuzo.meunet>
References: <m3hftsg2i5.fsf@gabuzo.meunet>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox