From: | Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com> |
---|---|
To: | Tjibbe Rijpma <t(dot)b(dot)rijpma(at)student(dot)tudelft(dot)nl>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: How the get variables out of a plggsql RECORD by column number |
Date: | 2005-01-18 14:41:08 |
Message-ID: | 20050118144108.17423.qmail@web20828.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
--- Tjibbe Rijpma <t(dot)b(dot)rijpma(at)student(dot)tudelft(dot)nl>
wrote:
> A record type contians the 1st row form dynamic
> query result.
>
> From that row I want to select the 1st column.
>
> How do I do that?
By name, i.e. "_row.firstfieldname". Perhaps you are
looking for a generic function, that can be applied to
any table? Pl/pgsql is not equipped to do that. I
believe that you can achieve what you want with
pl/tcl, pl/python or pl/perl (not sure about the
last).
>
>
> CREATE OR REPLACE FUNCTION dswz.save_query (TEXT)
> RETURNS BOOL AS '
> DECLARE
> _query ALIAS FOR $1;
> _temp_query TEXT;
> _row RECORD;
> _id INT8;
> _type INT8;
>
> BEGIN
> /* select the 1st row*/
> _temp_query := ''SELECT * FROM ('' || _query || '')
> AS table_source LIMIT 1'';
>
> FOR _row IN EXECUTE temp_query LOOP
>
> /* select the 1st column */
> _id := ????_row[0]??????
>
> END LOOP;
>
> /* Saves the query and his type */
> SELECT INTO _type type FROM objects WHERE id = _id;
> INSERT INTO queries VALUES (_query, _type);
>
>
> RETURN TRUE;
> END
>
> ' LANGUAGE 'plpgsql' SECURITY DEFINER;
__________________________________
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
From | Date | Subject | |
---|---|---|---|
Next Message | Shaun McGuile | 2005-01-18 15:17:20 | Windows 2000 Pro Error on Install |
Previous Message | Luiz K. Matsumura | 2005-01-18 13:54:27 | Change database encoding |