Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions that declare a non-trivial cursor fail to compile #45

Open
hawicz opened this issue Jun 15, 2020 · 2 comments
Open

Functions that declare a non-trivial cursor fail to compile #45

hawicz opened this issue Jun 15, 2020 · 2 comments

Comments

@hawicz
Copy link
Contributor

hawicz commented Jun 15, 2020

A function that looks like this:

create or replace function foo()
returns void
language plpgsql
as $$
DECLARE
   DECLARE mycur CURSOR FOR SELECT * from pg_database;
BEGIN
   return;
END;
$$;

Results in:

        ****
        Error compiling procedure public.foo
        Source: /home/user/piggly/cache/Dumper/511efb81e82810ddd8b9359d7c6a7758.plpgsql
        Exception Message:
        Expected one of [ \t\n\v\f\r], 'as', 'not', ':=', '=', '(', '[', [a-z\200-\377_0-9$%], '/*', '--', ';' at line 2, column 36 (byte 44) after declare

declare mycur cursor for select
****

On the other hand, changing it to say "... SELECT 1..." instead of "...SELECT *..." works (though of course it's not very useful to have a query that does effectively nothing).

@kputnam
Copy link
Owner

kputnam commented Jun 16, 2020

Thanks for reporting this. I wonder if the repeated DECLARE is causing the issue here. Can you try rewriting your example like so?

create or replace function foo()
returns void
language plpgsql
as $$
DECLARE
   mycur CURSOR FOR SELECT * from pg_database;
BEGIN
   return;
END;
$$;

If that doesn't work, it looks fixable with minor changes to the grammar specification. If you'd like to take a stab at it, I'll be happy to review and merge a PR. Otherwise, I will get to it but will probably take a week or two.

@hawicz
Copy link
Contributor Author

hawicz commented Jun 17, 2020

Looks fairly simple to tweak, I'll take a look.

hawicz added a commit to hawicz/piggly that referenced this issue Jun 17, 2020
…iables in a declaration section.

Also allow "COLLATE" and "DEFAULT" in regular variable declarations.
hawicz added a commit to hawicz/piggly that referenced this issue Jun 17, 2020
…iables in a declaration section.

Also allow "COLLATE" and "DEFAULT" in regular variable declarations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants