Using refcursors in application code (php, python, whatever...)

From: "Webb Sprague" <webb(dot)sprague(at)gmail(dot)com>
To: "pgsql General" <pgsql-general(at)postgresql(dot)org>
Subject: Using refcursors in application code (php, python, whatever...)
Date: 2008-11-12 15:12:33
Message-ID: b11ea23c0811120712v7c102ee2q543a7c9d45df2487@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

Does anyone have any advice on using application code with a
refcursor? This is a follow up to my "is there a safe-ish way to
execute arbitrary sql" ? Now that I have way to execute my arbitrary
sql, I need to generate an html table with the arbitrary result inside
some PHP (or whatever), so I need to loop over the results of the
cursor (or do some weird return setof magic which I just figured out).

Sorry to ask here, but I think it is more likely that the readers will
even know what a refcursor is than on a massive php email list.

Here is what I have working in psql:

select query_table_data('select * from mkn_data.datatable_00013', 'boobear');

query_table_data
------------------
boobear
(1 row)

mkn=# FETCH FORWARD ALL FROM boobear;
col1 | col2
-------+------
bob | 34
alice | 32
(2 rows)

Now I need something that says

$curs.fetchall()

Browse pgsql-general by date

  From Date Subject
Next Message Jack Orenstein 2008-11-12 15:13:29 Table bloat and vacuum
Previous Message Adriana Alfonzo 2008-11-12 15:10:45 Re: Table bloat and vacuum