From: | Toby Tremayne <lists(at)devfrag(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: refursor from dynamic query |
Date: | 2002-12-11 23:42:45 |
Message-ID: | 101314662871.20021212104245@devfrag.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
hmm ok I've played a little more with this and I've discovered if I
run the following in psql:
begin;
select poptions(1);
-- output -- <unnamed cursor 18>
-- output -- 1 row(s)
fetch all in "<unnamed cursor 18>";
commit;
it spits out the rows I was expecting it to have. So obviously the
function is returning a refcursor that contains the data I'd
expected. My problem is I'm calling this function from a cold fusion
template and I'm receiving an empty query object (which I'm assuming
is the refcursor). How can I easily get at the records within the
cursor? Is there something I'm missing?
cheers,
Toby
> Hi all,
> just subscribed to the list - I've been writing my first
> function/stored procedure and I've hit a bit of a problem. I'm
> trying to build a dynamic query, then execute it but I need to
> return a refcursor containing the records the dynamic query finds.
> My code is below - I'd appreciate it if anyone could point me in
> the right direction....
> CREATE FUNCTION poptions (INTEGER)
> RETURNS REFCURSOR AS '
> DECLARE
> -- parameters
> p_author_id ALIAS FOR $1;
> -- local variables
> rc REFCURSOR;
> row_data poem_option_def%ROWTYPE;
> qString varchar(4000);
> BEGIN
> qString := ''SELECT p.poem_id,p.poem_title'';
> FOR row_data IN SELECT option_id,option_name FROM poem_option_def LOOP
> qString := qString || '', (SELECT po.setting FROM poem_option po WHERE po.poem_id = p.poem_id and po.option_id = '' || row_data.option_id || '') AS '' || row_data.option_name;
> END LOOP;
> qString := qString || '' FROM poem p WHERE p.author_id = '' || p_author_id;
> OPEN rc FOR EXECUTE qString;
> RETURN rc;
> end;
> ' LANGUAGE 'plpgsql';
> cheers,
> Toby
> ---------------------------------------
> Life is poetry - write it in your own words.
> ---------------------------------------
> Toby Tremayne
> Senior Technical Consultant
> Code Poet and Zen Master of the Heavy Sleep
> Lyricist Software
> www.lyricist.com.au
> 0416 048 090
> ICQ: 13107913
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
---------------------------------------
Life is poetry - write it in your own words.
---------------------------------------
Toby Tremayne
Senior Technical Consultant
Code Poet and Zen Master of the Heavy Sleep
Lyricist Software
www.lyricist.com.au
0416 048 090
ICQ: 13107913
From | Date | Subject | |
---|---|---|---|
Next Message | Joshua D. Drake | 2002-12-12 00:11:44 | Potentially serious migration issue from 7.1.3 to 7.2 (or 7.3) |
Previous Message | Doug Fields | 2002-12-11 23:03:30 | Re: Batch Inserts |