Re: Problem with triggers and cursors - Mailing list pgsql-novice

From Tom Lane
Subject Re: Problem with triggers and cursors
Date
Msg-id 27658.1158238911@sss.pgh.pa.us
Whole thread Raw
In response to Problem with triggers and cursors  (Karsten Hoffrath <khoffrath@khoffrath.de>)
List pgsql-novice
Karsten Hoffrath <khoffrath@khoffrath.de> writes:
> Is using a cursor the preferred way to fetch data from another table?

It's the hard way, not to mention that you've not got the syntax of OPEN
quite right.

Instead of

> DECLARE
>   cSrvID CURSOR FOR SELECT * FROM v_systemparameter WHERE
> systemparameter = 'serverid';
>   rSrvID RECORD;
>   cRowID refcursor;
>   rRowID RECORD;
> ...
>     OPEN cSrvID;
>     FETCH cSrvID INTO rSrvID;
>     CLOSE cSrvID;
>     OPEN cRowID CURSOR FOR SELECT nextval('seq_' || TG_RELNAME);
>     FETCH cRowID INTO rRowID;
>     CLOSE cRowID;

I'd just do

DECLARE
  rSrvID RECORD;
  rowID bigint; -- or integer, it's not clear which you want
...
    SELECT * INTO rSrvID FROM v_systemparameter WHERE systemparameter = 'serverid';
    rowID := nextval('seq_' || TG_RELNAME);
...


            regards, tom lane

pgsql-novice by date:

Previous
From: "roy simkes"
Date:
Subject: Re: replication/synchronisation
Next
From: Shane Ambler
Date:
Subject: Re: replication/synchronisation