libpg_query
libpg_query copied to clipboard
Parsing plpgsql function with cursor returns an error
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.
FYI, the OP referenced the PR #256 that apparently fixes this.
Closing this since the mentioned PR #256 was merged.