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