ROWTYPE as parameter to function

Nigel J. Andrews <nandrews@investsystems.co.uk>

From: "Nigel J. Andrews" <nandrews@investsystems.co.uk>
To: pgsql-general@postgresql.org
Date: 2002-04-19T21:11:19Z
Lists: pgsql-general

I see that RECORD can't be used as a type of an argument in a function,
however, I see nothing that says tablename%ROWTYPE can't. Indeed from the
reason given for RECORD not being allowed I would have thought the %ROWTYPE
would have been.

May be I'm just being silly in what I'm trying to do. What I have is a view 
called, say, myview which I am trying to trap inserts to so the real tables can
be written to. The view is the 'user interface' so to speak. So what I have is:

CREATE VIEW myview AS SELECT ...;

and what I'd like to do is:

CREATE FUNCTION myfunction (RECORD) RETURNS ... ;
CREATE RULE insert_myview AS ON INSERT TO myview DO INSTEAD
	SELECT myfunction(NEW);

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.

I don't think triggers are the things to use, partly because I don't know
anything about these SPI functions available for accessing other tables within
them but also because I think the rule system is the correct route to trap such
things on a view. So, am I being sensible in trying this design? Am I doing
something that isn't permitted, like with the RECORD type, by trying to get an
entire row into a function in one variable?


-- 
Nigel J. Andrews
Director

---
Logictree Systems Limited
Computer Consultants