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

Parsing plpgsql function with cursor returns an error #257

Open
lelit opened this issue Aug 26, 2024 · 2 comments
Open

Parsing plpgsql function with cursor returns an error #257

lelit opened this issue Aug 26, 2024 · 2 comments

Comments

@lelit
Copy link
Contributor

lelit commented Aug 26, 2024

Hi,

investigating on a similar issue reported against pglast, I found that effectively the following example

#include <pg_query.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
  PgQueryPlpgsqlParseResult result;

  result = pg_query_parse_plpgsql("\
   CREATE FUNCTION foo(cmd TEXT) RETURNS void AS $$\
   DECLARE\
     i INT;\
     c CURSOR FOR SELECT generate_series(1,10);\
   BEGIN\
     FOR i IN c LOOP\
       RAISE NOTICE 'i is %',i;\
     END LOOP;\
   END\
   $$ LANGUAGE plpgsql;");
  if (result.error) {
    printf("error: %s at %d\n", result.error->message, result.error->cursorpos);
  } else {
    printf("%s\n", result.plpgsql_funcs);
  }

  pg_query_free_plpgsql_parse_result(result);

  // Optional, this ensures all memory is freed upon program exit (useful when running Valgrind)
  pg_query_exit();

  return 0;
}

emits

error: syntax error at or near "c" at 0

I tried looking at open issues targeting plpgsql, but failed to find one related to cursors.

@lelit
Copy link
Contributor Author

lelit commented Aug 26, 2024

FYI, the OP referenced the PR #256 that apparently fixes this.

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
@lelit and others