X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2A43D52A54 for ; Fri, 25 Feb 2005 02:02:19 +0000 (GMT) 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 71993-02 for ; Fri, 25 Feb 2005 02:02:10 +0000 (GMT) Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.250.190.2]) by svr1.postgresql.org (Postfix) with ESMTP id 1185A5621A for ; Fri, 25 Feb 2005 02:02:09 +0000 (GMT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 6A8F631DBF; Fri, 25 Feb 2005 03:02:24 +0100 (MET) From: "Nico" X-Newsgroups: pgsql.interfaces.jdbc Subject: rule/trigger for batch update Date: Fri, 25 Feb 2005 03:00:15 +0100 Organization: Hub.Org Networking Services Lines: 26 Message-ID: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original To: pgsql-jdbc@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=3.319 tagged_above=0 required=5 tests=AWL, FORGED_YAHOO_RCVD, PRIORITY_NO_NAME X-Spam-Level: *** X-Archive-Number: 200502/194 X-Sequence-Number: 12374 Hi, I want to make a trigger or a rule. However here is the tricky part: I want it to happen after a batch of updates and not during one of them. It is already set (by means of a unique index) that maximum one record can contain the value 1. Point is that after every update I still have exactly one record where the field value is 1. Here is what is supposed to happen in the same batch: UserRoleID (where value is 1) becomes 2 or 3. Which leaves no record to have a 1 value in this field. The field becomes 1 in another record. Now both actions must happen or neither. Here is the table creation code: CREATE TABLE "tblUser" ( "UserID" serial NOT NULL, "UserName" character varying(50) NOT NULL, "UserPass" character varying(50) NOT NULL, "UserRoleID" integer DEFAULT 3 NOT NULL ); CREATE UNIQUE INDEX indsuperadmin ON "tblUser" USING btree ("UserRoleID") WHERE ("UserRoleID" = 1); Thanks in advance, Nico.