Thread: cursor question

cursor question

From
Andreas Wenk
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

short question. Why is this not possible:

CREATE OR REPLACE FUNCTION user_cursor_open(text) RETURNS refcursor AS $$
DECLARE
        curs1 CURSOR FOR SELECT * FROM $1;
BEGIN
        OPEN curs1;
        RETURN curs1;
END; $$ LANGUAGE plpgsql;

Or, how do I set a parameter when using cursor?

Thanks in advance

- --
St.Pauli - Hamburg - Germany

Andreas Wenk


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJpWlyVa7znmSP9AwRAv2MAJ9jHICtLeIEv+QVzeqBWSkheXDmpgCgwMUH
t0/HWRPsx56jGhSVUQXyb9I=
=XMXi
-----END PGP SIGNATURE-----

Re: cursor question

From
Pavel Stehule
Date:
Hello

when you would to change name of table - you have to use dynamic query

38.7.2.2. OPEN FOR EXECUTE

OPEN unbound_cursor [ [ NO ] SCROLL ] FOR EXECUTE query_string;


http://www.postgresql.org/docs/8.3/interactive/plpgsql-cursors.html

regards
Pavel Stehule

2009/2/25 Andreas Wenk <a.wenk@netzmeister-st-pauli.de>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> short question. Why is this not possible:
>
> CREATE OR REPLACE FUNCTION user_cursor_open(text) RETURNS refcursor AS $$
> DECLARE
>        curs1 CURSOR FOR SELECT * FROM $1;
> BEGIN
>        OPEN curs1;
>        RETURN curs1;
> END; $$ LANGUAGE plpgsql;
>
> Or, how do I set a parameter when using cursor?
>
> Thanks in advance
>
> - --
> St.Pauli - Hamburg - Germany
>
> Andreas Wenk
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFJpWlyVa7znmSP9AwRAv2MAJ9jHICtLeIEv+QVzeqBWSkheXDmpgCgwMUH
> t0/HWRPsx56jGhSVUQXyb9I=
> =XMXi
> -----END PGP SIGNATURE-----
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

Re: cursor question

From
Andreas Wenk
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pavel Stehule schrieb:
> Hello
>
> when you would to change name of table - you have to use dynamic query
>
> 38.7.2.2. OPEN FOR EXECUTE
>
> OPEN unbound_cursor [ [ NO ] SCROLL ] FOR EXECUTE query_string;
>
>
> http://www.postgresql.org/docs/8.3/interactive/plpgsql-cursors.html
>
> regards
> Pavel Stehule

Hi Pavel,

thanks a lot. It works for me like this:

CREATE OR REPLACE FUNCTION user_cursor_test(refcursor,text) RETURNS refcursor AS $$
BEGIN
        OPEN $1 FOR EXECUTE 'SELECT name FROM ' || $2;
        RETURN $1;
END; $$ LANGUAGE plpgsql;

Cheers

Andy


> 2009/2/25 Andreas Wenk <a.wenk@netzmeister-st-pauli.de>:
> Hi,
>
> short question. Why is this not possible:
>
> CREATE OR REPLACE FUNCTION user_cursor_open(text) RETURNS refcursor AS $$
> DECLARE
>        curs1 CURSOR FOR SELECT * FROM $1;
> BEGIN
>        OPEN curs1;
>        RETURN curs1;
> END; $$ LANGUAGE plpgsql;
>
> Or, how do I set a parameter when using cursor?
>
> Thanks in advance
>
>>
- --
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
>>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJpYU2Va7znmSP9AwRAgGAAJ9En2TEupu7t994DIxi9ql5LH5sXACdHIi1
jNiaLX2mEmYWRxHDcGavbsM=
=XUcF
-----END PGP SIGNATURE-----