Triggers, plpgsql, etc. - Mailing list pgsql-sql

From Christophe Labouisse
Subject Triggers, plpgsql, etc.
Date
Msg-id m3hftsg2i5.fsf@gabuzo.meunet
Whole thread Raw
Responses Re: [SQL] Triggers, plpgsql, etc.
List 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 ?

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/


pgsql-sql by date:

Previous
From: Frank Barknecht
Date:
Subject: Re: [SQL] Text type
Next
From: jwieck@debis.com (Jan Wieck)
Date:
Subject: Re: [SQL] Triggers, plpgsql, etc.