Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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

>   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

  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

pgsql-novice by date

Next:From: Chris BrowneDate: 2006-09-14 16:16:03
Subject: Re: replication/synchronisation
Previous:From: roy simkesDate: 2006-09-14 09:48:45
Subject: Re: replication/synchronisation

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group