Re: Question on Rules - Mailing list pgsql-general

From David Johnston
Subject Re: Question on Rules
Date
Msg-id 00b101ccef86$66146310$323d2930$@yahoo.com
Whole thread Raw
In response to Question on Rules  (<mgould@isstrucksoftware.net>)
List pgsql-general
-----Original Message-----
From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of
mgould@isstrucksoftware.net
Sent: Saturday, February 18, 2012 5:17 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] Question on Rules

I am creating a rule which will copy a record when it is changed to a audittable.  My question is that the first column
isa UUID data type with a defined as auditaccessorid uuid DEFAULT 
isscontrib.uuid_generate_v4() NOT NULL,

Right now I've got that set to NULL to allow the parser to "compile".
What value should I have in here since I want a newly created UUID?

CREATE RULE log_accessor AS ON UPDATE TO iss.accessor
    WHERE NEW.* <> OLD.*
    DO INSERT INTO iss.auditaccessor VALUES (NULL,
                                          'C',
                                          new.loaddtlid,
                                          new.seqno,
                                          new.billable,
                                          new.payind,
                                          new.code,
                                          new.description,
                                          new.ref,
                                          new.tractororcarrierflag,
                                          new.tractororcarrierno,
                                          new.tractorpct,
                                          new.charge,
                                          new.type,
                                          new.checkdate,
                                          new.checkno,
                                          new.processed,
                                          new.itemflag,
                                          new.tractortermloc,
                                          new.cost,
                                          new.batchno,
                                          new.editdatetime,
                                          new.edituser);

Best Regards,

Michael Gould
Intermodal Software Solutions, LLC
904-226-0978


--------------------------------------------------------------------

INSERT INTO table (serial_col1) VALUES (DEFAULT);

Also, I presume you have a good reason for using a RULE instead of a TRIGGER?  If not you should default to a TRIGGER
forthis kind of behavior. 

David J.



pgsql-general by date:

Previous
From: Jayashankar K B
Date:
Subject: Postgres 9.1 package for i.MX51X processor from Freescale
Next
From: Venkat Balaji
Date:
Subject: Re: [GENERA]: Postgresql-9.1.1 synchronous replication issue