Re: ROWTYPE as parameter to function

From: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: ROWTYPE as parameter to function
Date: 2002-04-20 15:49:25
Message-ID: Pine.LNX.4.21.0204201610220.572-100000@ponder.fairway2k.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Fri, 19 Apr 2002, Tom Lane wrote:

> "Nigel J. Andrews" <nandrews(at)investsystems(dot)co(dot)uk> writes:
> > Obviously I can't use the RECORD type but when I create the function with:
> > CREATE FUNCTION myfunction (myview%ROWTYPE) RETURNS ... ;
> > the '%' gets reported in an error message.
>
> Leave off the %ROWTYPE. Also read the info about composite-type
> arguments at
> http://www.ca.postgresql.org/users-lounge/docs/7.2/postgres/xfunc-sql.html

Thanks Tom. I didn't read that particular page before, I had been concentrating
on the PL/pgSQL pages.

As soon as I'd read that page I had the function being created. Unfortunately,
I can't now get the rule to be created. Again, I can't find the relevent
information in the docs, even though it's probably obvious again, so any help
on why this:

CREATE RULE insert_listing AS ON insert TO listing_view
DO INSTEAD SELECT insert_listing_fn(NEW);

gives the error: 'parser: parse error at or near ")"' would be appreciated.

Using:
1) SELECT 1,2,3
2) SELECT NEW.title
3) SELECT insert_listing_fn()
4) SELECT insert_listing_fn(NEW.title)

as the rule's action do not give this error, although 3 and 4 do of course give
a different error since there aren't version of the function defined with those
parameters.

I know I could just expand the NEW record in the call to the function, giving
each attribute as a parameter. However, I'd be more interested in knowing how
to do this properly.

--
Nigel J. Andrews
Director

---
Logictree Systems Limited
Computer Consultants

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-04-20 15:57:11 Re: On-disk Tuple Size
Previous Message Tom Lane 2002-04-20 15:27:51 Re: On-Disk Tuple Size