Returning Setof Record Dynamically - Mailing list pgsql-sql

From A E
Subject Returning Setof Record Dynamically
Date
Msg-id 20031218182016.53777.qmail@web12107.mail.yahoo.com
Whole thread Raw
List pgsql-sql
Hi,
 
I am attempting to use Setof Record dynamically. I am developing an application where I will not know what the end-user is trying to work with from a web front end. Thus I will not know before hand the structure of the table I am trying to pull the record from.
 
My Code:
 
CREATE FUNCTION retrievecollection(varchar, varchar, varchar) RETURNS record AS'
Declare
tablealias ALIAS FOR $1;
crmid ALIAS FOR $2;
username ALIAs FOR $3;
allowed integer;
objectdefinition record;
realtablename char;
begin
select into allowed secverf(username, tablealias);
if allowed = 0 then
 RAISE NOTICE ''User not authorized to perform retrieve.'', allowed;
 RETURN false;
else
 select into realtablename tablename from applicationaliases where tablealias = qoute_literal(tablealias);
 if length(crmid) = 0 then
  FOR objectdefinition IN SELECT * from qoute_ident(realtablename) LOOP
   RETURN NEXT objectdefinition;
  END LOOP;
 else
  FOR objectdefinition IN SELECT * from qoute_ident(realtablename) where crmid = qoute_literal(crmid) LOOP
   RETURN NEXT objectdefinition;
  END LOOP;
 end if;
end if;
RETURN record;
end;'
LANGUAGE 'plpgsql' VOLATILE;

I know that I would execute the procedure with select * from retrievecollection as x(x typex, y typey) but how do I do this if I don't know which table was passed to the function?

TIA

Alex Erwin

 

pgsql-sql by date:

Previous
From: teknokrat
Date:
Subject: how do i get differences between rows
Next
From: "Jonas Lindholm"
Date:
Subject: Problem with functions.