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: ROWTYPE as parameter to function
Date: 2002-04-19 21:11:19
Message-ID: Pine.LNX.4.21.0204192043070.20382-100000@ponder.fairway2k.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Post 2002-04-19 21:17:15 Building perl mods pg:PG or DBD:PG on non-PostgreSQLable machines
Previous Message Tom Lane 2002-04-19 20:47:06 Re: postgres startup script, long delay when auth = password