Triggers, plpgsql, etc.

From: Christophe Labouisse <labouiss(at)club-internet(dot)fr>
To: pgsql-sql(at)postgreSQL(dot)org
Subject: Triggers, plpgsql, etc.
Date: 1999-01-15 12:10:58
Message-ID: m3hftsg2i5.fsf@gabuzo.meunet
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 ?

Attachment Content-Type Size
unknown_filename text/plain 150 bytes

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jan Wieck 1999-01-15 17:36:15 Re: [SQL] Triggers, plpgsql, etc.
Previous Message Morris, Sam@EDD 1999-01-14 19:04:16 many to many relationship Query ?