pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Rules: passing new/old to functions
2+ messages / 2 participants
[nested] [flat]

* Rules: passing new/old to functions
@ 2003-06-22 20:28  Gunter Diehl <gdid@gmx.de>
  0 siblings, 1 reply; 2+ messages in thread

From: Gunter Diehl @ 2003-06-22 20:28 UTC (permalink / raw)
  To: pgsql-sql

How to pass the special variables new / old to functions?

e.g. I'd like to to something like this (v is a view):

create funtion f1(v, v) returns void as '...'
create rule vupt as on update to v do instead select f1(new, old)

While accepting this definitions, pg says it can not handle "whole-tuple
references" at runtime.

using: select f(new) from new    doesn't work either: pg says relation new
doesn't exist.

Since I need to handle tables with more than 20 columns, it would be uggly
if I had to pass every single value to the function as follows:
select f1(new.1, ..., new.n, old.1, ..., old.n)
create function f1(typeof 1, ..., typeof n, typeof 1, ..., typeofn)


I'd be glad for any kind of suggestion.

regards,
	Gunter


-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Rules: passing new/old to functions
@ 2003-06-27 03:49  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Gunter Diehl <gdid@gmx.de>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2003-06-27 03:49 UTC (permalink / raw)
  To: Gunter Diehl <gdid@gmx.de>; +Cc: pgsql-sql

Gunter Diehl <gdid@gmx.de> writes:
> create funtion f1(v, v) returns void as '...'
> create rule vupt as on update to v do instead select f1(new, old)
> While accepting this definitions, pg says it can not handle "whole-tuple
> references" at runtime.

FWIW, the "old" case works fine.  "new" doesn't work so well because the
new row hasn't been formed into a tuple at the point where the rule
runs; it only exists as a list of variables.  (This is a rather handwavy
explanation, but I think it captures the key point.)  While this could
probably be fixed with some effort, I doubt it's going to happen soon.
Is there any chance of doing what you want with a trigger instead of a
rule?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2003-06-27 03:49 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-06-22 20:28 Rules: passing new/old to functions Gunter Diehl <gdid@gmx.de>
2003-06-27 03:49 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox