Question on Rules

Started by Michael Gouldabout 14 years ago5 messagesgeneral
Jump to latest
#1Michael Gould
mgould@isstrucksoftware.net

I am creating a rule which will copy a record when it is changed to a
audittable. My question is that the first column is a 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

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Michael Gould (#1)
Re: Question on Rules

-----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 is a 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 for this kind of behavior.

David J.

#3Michael Gould
mgould@isstrucksoftware.net
In reply to: David G. Johnston (#2)
Re: Question on Rules

Thanks I will change to a trigger

Best Regards

Mike Gould

Sent from Samsung mobile

David Johnston <polobo@yahoo.com> wrote:

Show quoted text

-----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 is a 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 for this kind of behavior.

David J.

#4Michael Gould
mgould@isstrucksoftware.net
In reply to: Michael Gould (#3)
Re: Question on Rules

Attachments:

top.letterheadimage/png; name=top.letterheadDownload+3-1
#5John R Pierce
pierce@hogranch.com
In reply to: Michael Gould (#4)
Re: Question on Rules

On 02/20/12 9:07 AM, mgould@isstrucksoftware.net wrote:

Are rules deprecated?

rules are very tricky, and primarily exist now for internal use.

--
john r pierce N 37, W 122
santa cruz ca mid-left coast