Loop through records

From: Emiliano Amilcarelli <emiliano(dot)amilcarelli(at)vtin(dot)it>
To: pgsql-novice(at)postgresql(dot)org
Subject: Loop through records
Date: 2005-11-11 15:43:29
Message-ID: 4374BC21.3080903@vtin.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi all,
I'm a PostgreSQL novice (obviously)...
I' trying to write some test functions to iterate over recordsets...

this is one:

CREATE OR REPLACE FUNCTION "public"."new_allarma" (soglia name) RETURNS
text AS
$body$
DECLARE
rec RECORD;
agent text;
BEGIN

FOR rec in SELECT * from "ERRORS" where "MAX_ERRORS" > = soglia limit 3
LOOP
RAISE NOTICE '--> RECORD --> ';
END LOOP;
RAISE NOTICE 'Complete';
RETURN 'OK';
END;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

It doesn't even print the string --> RECORD --> as I supposed it to do...

but raises the error:ERROR: record "rec" is not assigned yet
DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.
CONTEXT: PL/pgSQL function "new_allarma2" line 6 at for over select rows

Now i ask: how can I iterate through a recordset and print something,
suppose the entire record ( or better its fields) ?

Thanks in advance.

Best Regards,

Emil.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Frank Hu 2005-11-11 17:03:34 psql output Horizontal scrollable ?
Previous Message Frank Bax 2005-11-11 15:13:54 VIEW AS SELECT -vs- INSERT INTO table query