From: | A E <cooljoint(at)yahoo(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Error with returning SETOF Record |
Date: | 2003-12-27 21:57:29 |
Message-ID: | 20031227215729.95642.qmail@web12104.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
I guess the question I have then is how do I return data from a select statement using the record datatype? This is only a test function I was trying to get info from, but my application is based on passing the table name to the function dynamically. How do I do this? The documentation is sketchy when it comes to the record datatype.
TIA
Alex
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
A E writes:
> CREATE FUNCTION tester(varchar) RETURNS SETOF record as'
> DECLARE
> ft record;
> begin
> FOR ft IN SELECT * FROM visaapplicants LOOP
> RETURN NEXT ft;
> END LOOP;
> return null;
> end;'
> LANGUAGE 'plpgsql' VOLATILE;
>
> select * from tester('a') as (c varchar);
>
> ERROR: wrong record type supplied in RETURN NEXT
> CONTEXT: PL/pgSQL function "tester" line 6 at return next
That's pretty much what I'd expect, unless table visaapplicants contains
only a single varchar column. The example works fine for me if I define
visaapplicants that way.
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Treat | 2003-12-27 21:57:54 | Re: Is my MySQL Gaining ? |
Previous Message | Manfred Spraul | 2003-12-27 21:36:36 | Re: update i386 spinlock for hyperthreading |