From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | inspector morse <inspectormorse86(at)gmail(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to read refcursor column's using string column name? |
Date: | 2015-03-10 20:02:42 |
Message-ID: | CAFj8pRBkJSyAagKJNms3rBni1jJyhnBNeksrnWmFGy8ZO=P=gg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
2015-03-10 20:56 GMT+01:00 inspector morse <inspectormorse86(at)gmail(dot)com>:
> 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?
>
you can translate record to Hstore type and then you can take a value by
dynamic name. Usual older solution was using plperl or plpython.
Regards
Pavel
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Kupershmidt | 2015-03-10 20:50:50 | Re: reltoastidxid altenates in postgresql 9.4 |
Previous Message | inspector morse | 2015-03-10 19:56:58 | How to read refcursor column's using string column name? |