cursor declare

Started by Peter Koukoulisover 8 years ago2 messagesgeneral
Jump to latest
#1Peter Koukoulis
pkoukoulis@gmail.com

Hi

This is my first cursor attempt:

according to docs

DECLARE
curs1 refcursor;
curs2 CURSOR FOR SELECT * FROM tenk1;
curs3 CURSOR (key integer) FOR SELECT * FROM tenk1 WHERE unique1 = key;

this should work, but getting error:

ft_node=# declare cur_test1 CURSOR (key integer) for select * from test1
where x=key;
ERROR: syntax error at or near "("
LINE 1: declare cur_test1 CURSOR (key integer) for select * from tes...

Table is defined as:
psql (9.6.4)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384,
bits: 256, compression: off)
Type "help" for help.

ft_node=# \d+ test1
Table "public.test1"
Column | Type | Modifiers | Storage | Stats target |
Description
--------+-----------------------+-----------+----------+--------------+-------------
x | integer | | plain | |
y | character varying(20) | | extended | |

Can somebody please help?

P

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Koukoulis (#1)
Re: cursor declare

Peter Koukoulis <pkoukoulis@gmail.com> writes:

This is my first cursor attempt:

according to docs

DECLARE
curs1 refcursor;
curs2 CURSOR FOR SELECT * FROM tenk1;
curs3 CURSOR (key integer) FOR SELECT * FROM tenk1 WHERE unique1 = key;

this should work, but getting error:

ft_node=# declare cur_test1 CURSOR (key integer) for select * from test1
where x=key;
ERROR: syntax error at or near "("
LINE 1: declare cur_test1 CURSOR (key integer) for select * from tes...

It looks like you're trying to use the plpgsql syntax for a cursor
variable as part of a DECLARE CURSOR SQL-level command. They're not
the same thing at all. In particular, there isn't any concept of
parameters in the SQL DECLARE CURSOR command.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general