How the get variables out of a plggsql RECORD by column number

From: "Tjibbe Rijpma" <t(dot)b(dot)rijpma(at)student(dot)tudelft(dot)nl>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: How the get variables out of a plggsql RECORD by column number
Date: 2005-01-17 23:45:59
Message-ID: 01c601c4fcee$b2dbc5e0$0100a8c0@TJIBBE
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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?

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;

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Ramon Orticio 2005-01-18 02:16:00 can't add connection to server in windowsXP using pgadminIII
Previous Message Jaime Casanova 2005-01-17 22:08:28 Re: Updating views : cannot figure out what goes wrong