How to read refcursor column's using string column name?

From: inspector morse <inspectormorse86(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: How to read refcursor column's using string column name?
Date: 2015-03-10 19:56:58
Message-ID: CAHYn==705SKJs6VErNwRJ8-0Qj-qrYDb9mmys_ifnU2bAOOzqA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How do I access a cursor's column using a string column?

Example:

CREATE FUNCTION write_html_select(items cursor, data_value_field text,
data_text_field text)
AS
$$
DECLARE r RECORD;
html TEXT;
BEGIN
FOR r in items LOOP
html = "<option value=" || r[data_value_field] || "/>";
END LOOP;

RETURN html;
END;
$$
LANGUAGE plpgsql;

As you can see, I want to access RECORD r's columns by a STRING column name
value (data_value_field etc)....is there anyway to do this?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2015-03-10 20:02:42 Re: How to read refcursor column's using string column name?
Previous Message Jerry Sievers 2015-03-10 17:46:57 Re: Strange security issue with Superuser access