How to access OLD and NEW with rule on update

Started by Han Hollover 23 years ago3 messagesgeneral
Jump to latest
#1Han Holl
han.holl@prismant.nl

Hi,

I need to call a function when updating on a view, like :

create rule udps_upd as on update to udps do
instead select function_call();

My problem: how do I get a reference to OLD and NEW ?

I tried function_call(OLD, NEW) -- parse error
function_call(OLD.oid, NEW.oid) -- no such attributes
and function_call(OLD.ctid, NEW.ctid).

The last executes, but unfortunately I have no idea how to
proceed in the called function. In all fmgr macros, not one
seems to be concerned with a beast like a tid.

Or is there some information available in the passed
FunctionCallInfoData.context ?

Cheers,

Han Holl

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Han Holl (#1)
Re: How to access OLD and NEW with rule on update

"Han Holl" <han.holl@prismant.nl> writes:

I need to call a function when updating on a view, like :

create rule udps_upd as on update to udps do
instead select function_call();

My problem: how do I get a reference to OLD and NEW ?

I tried function_call(OLD, NEW) -- parse error

I think you'll need to do it as

function_call(old.col1, old.col2, ..., new.col1, new.col2, ...)

Pretty tedious :-( but the rule rewriter doesn't support whole-row
references to OLD or NEW.

regards, tom lane

#3Han Holl
han.holl@prismant.nl
In reply to: Tom Lane (#2)
Re: How to access OLD and NEW with rule on update

On Friday 29 November 2002 02:28 am, you wrote:

"Han Holl" <han.holl@prismant.nl> writes:

I need to call a function when updating on a view, like :

create rule udps_upd as on update to udps do
instead select function_call();

My problem: how do I get a reference to OLD and NEW ?

I tried function_call(OLD, NEW) -- parse error

I think you'll need to do it as

function_call(old.col1, old.col2, ..., new.col1, new.col2, ...)

Pretty tedious :-( but the rule rewriter doesn't support whole-row
references to OLD or NEW.

Thanks for the info. I was afraid of that.
I't not the tediousness that's the problem though, but that I don't
know the column names. And there might be 300 columns in this
view.
I guess it's read-only for the time being.

Cheers,

Han Holl