Skip site navigation (1) Skip section navigation (2)

Resolution for "ERROR: cannot handle whole-row reference" ?

From: Sean Chittenden <sean(at)chittenden(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Resolution for "ERROR: cannot handle whole-row reference" ?
Date: 2004-03-28 13:28:50
Message-ID: D952E991-80BB-11D8-8DF7-000A95C705DC@chittenden.org (view raw or flat)
Thread:
Lists: pgsql-general
Hopefully I'm being blind and missing something obvious.  Here's the 
scenario:

-- I have a large table/view with a large-ish number of columns 
(routinely
-- more than 32 cols) and need to pass every col through to a function, 
and
-- am not inclined to recompile with INDEX_MAX_KEYS/FUNC_MAX_ARGS set
-- to 64 unless I *absolutely* have to, and even then, I don't want to 
impose
-- an arbitrary limitation that I should be able to get around with the 
RECORD
-- type... "in theory."
CREATE TABLE t1 (c1 int, c2 int, c3 int, c4 int, c5 int, c6 int, c7 
int, c8 int, c9 int, c10 int, c11 int, c12 int, c13 int, c14 int, c15 
int, c16 int, c17 int, c18 int, c19 int, c20 int, c21 int, c22 int, c23 
int, c24 int, c25 int, c26 int, c27 int, c28 int, c29 int, c30 int, c31 
int, c32 int, c33 int, c34 int, c35 int, c36 int, c37 int);

CREATE FUNCTION f1(RECORD) RETURNS BOOL LANGUAGE 'plpgsql' AS 'BEGIN 
RETURN TRUE; END;';

CREATE RULE t1_ins AS ON INSERT TO t1 DO INSTEAD SELECT f1(NEW);
ERROR:  function f1(t1) does not exist
HINT:  No function matches the given name and argument types. You may 
need to add explicit type casts.

-- You can't cast NEW to a RECORD type and there's no member of the 
NEW/OLD
-- pseudorelation that'll return a RECORD, so, instead, let me try a 
whole row
-- as the argument:
CREATE FUNCTION f1(t1) RETURNS BOOL LANGUAGE 'plpgsql' AS 'BEGIN RETURN 
TRUE; END;';
CREATE RULE r_ins AS ON INSERT TO t1 DO INSTEAD SELECT f1(NEW);

INSERT INTO t1 (c1) VALUES (1);
ERROR:  cannot handle whole-row reference


Doh!  Am I missing a different way of handling this in a 
flexible/scalable way?  The comment in 
src/backend/rewrite/rewriteManip.c:886 leads me to believe that this is 
a limitation.  I'd use a trigger, but t1 is actually a VIEW that I'm 
trying to intercept commands to with RULEs.  Any guidance in handling 
this case is greatly appreciated.  -sc

-- 
Sean Chittenden


Responses

pgsql-general by date

Next:From: Robert TurnbullDate: 2004-03-28 14:29:24
Subject: Prepare a query in linpq?
Previous:From: David GaramondDate: 2004-03-28 13:08:11
Subject: Re: win32 users list (Re: Native Win32 port - PLEASE!)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group