ROWTYPE as parameter to function - Mailing list pgsql-general

From Nigel J. Andrews
Subject ROWTYPE as parameter to function
Date
Msg-id Pine.LNX.4.21.0204192043070.20382-100000@ponder.fairway2k.co.uk
Whole thread Raw
In response to unable to repair table: missing chunk number  (Alex Krohn <alex@gossamer-threads.com>)
Responses Re: ROWTYPE as parameter to function  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: postgres startup script, long delay when auth = password
Next
From: Jeff Post
Date:
Subject: Building perl mods pg:PG or DBD:PG on non-PostgreSQLable machines