Re: Problem with triggers and cursors

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Karsten Hoffrath <khoffrath(at)khoffrath(dot)de>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Problem with triggers and cursors
Date: 2006-09-14 13:01:51
Message-ID: 27658.1158238911@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Karsten Hoffrath <khoffrath(at)khoffrath(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Chris Browne 2006-09-14 16:16:03 Re: replication/synchronisation
Previous Message roy simkes 2006-09-14 09:48:45 Re: replication/synchronisation