X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7984553696 for ; Mon, 2 May 2005 01:49:35 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31690-03 for ; Mon, 2 May 2005 04:49:28 +0000 (GMT) Received: from ausimss.pervasive.com (ausimss.pervasive.com [66.45.103.246]) by svr1.postgresql.org (Postfix) with ESMTP id A37425346A for ; Mon, 2 May 2005 01:49:28 -0300 (ADT) Received: from ausbayes1.aus.pervasive.com ([172.16.8.6]) by ausimss.pervasive.com with InterScan Messaging Security Suite; Sun, 01 May 2005 23:49:20 -0500 Received: from BLRMAIL1.aus.pervasive.com ([10.3.16.60]) by ausbayes1.aus.pervasive.com with Microsoft SMTPSVC(5.0.2195.6713); Sun, 1 May 2005 23:49:19 -0500 content-class: urn:content-classes:message Subject: Re: trigger/rule question MIME-Version: 1.0 Date: Mon, 2 May 2005 10:19:17 +0530 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-ID: <02767D4600E59A4487233B23AEF5C5992A4081@blrmail1.aus.pervasive.com> X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] trigger/rule question Thread-Index: AcVOx88DM2jDmJEzT22zdhY4LRRtIQACFkGQ From: "Ramakrishnan Muralidharan" To: , "pgsql-sql" X-OriginalArrivalTime: 02 May 2005 04:49:19.0971 (UTC) FILETIME=[4D779B30:01C54ED2] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.097 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/65 X-Sequence-Number: 21378 Hi, =20 I have written the following trigger assuming the application can pass = NULL value on mtime and it can be handled on the server side by the = trigger. CREATE TABLE TEST3 ( ID INT4 NOT NULL, DDATE TIMESTAMP=20 ) CREATE OR REPLACE FUNCTION Updatemtime()=20 RETURNS TRIGGER AS $Updatemtime$ DECLARE dDate timestamp; BEGIN dDate =3D 'now'; IF COALESCE(NEW.DDATE , dDate ) =3D dDate THEN NEW.DDATE =3D dDate; END IF; RETURN NEW; END; $Updatemtime$ LANGUAGE 'plpgsql'; CREATE TRIGGER Updatemtime BEFORE INSERT ON TEST3 FOR EACH ROW EXECUTE PROCEDURE Updatemtime(); INSERT INTO TEST3 VALUES( 1 , NULL ); INSERT INTO TEST3 VALUES( 2 , '2005-05-01'); =20 select * from TEST3 I will continue work on this and let you know if I can find another = better solution for this issue. Regards, R.Muralidharan =20 -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Enrico Weigelt Sent: Monday, May 02, 2005 9:02 AM To: pgsql-sql Subject: Re: [SQL] trigger/rule question * Ramakrishnan Muralidharan = wrote: Hi, > Going through you mail, I assume that you are updating the mtime=20 > only after inserting the record.=20 An "normal" update (=3Ddone by an application or user) should also=20 update the mtime. But there's an replication subsystem, which writes should go through untouched.=20 > It is always possible to check the mtime filed value of the inserted=20 > record and take action based on it in the trigger.=20 yeah, but how to detect whether the application has explicitly=20 written it ? The only chance I currently have in mind is to use some session=20 dependent data, i.e. username or some persistant storage (could be=20 easily done ie. w/ plphp) for this decision. The sync subsystem has to do some "special" login (ie. separate user or setting the=20 session wide variable) before doing its work. I would be happier to let a rule do this, so there's not an extra=20 function per written row. But all my experiments ran into infinite recoursion trouble. > Is it possible to send me detail about the trigger? The trigger isn't existing yet. I'm currently maintaining the mtime updates within the application, but I wanna get away from that. It=20 probably would be interesting, if a normal application couldn't=20 touch the mtime at all. cu --=20 --------------------------------------------------------------------- Enrico Weigelt =3D=3D metux IT service phone: +49 36207 519931 www: http://www.metux.de/ fax: +49 36207 519932 email: contact@metux.de --------------------------------------------------------------------- Realtime Forex/Stock Exchange trading powered by postgresSQL :)) http://www.fxignal.net/ --------------------------------------------------------------------- ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org