-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
parse_sql vs parse_plpgsql usage #88
Comments
Hi, unfortunately the plpgsql parser is not yet fully implemented, so I'm
afraid it is of little utility as of now.
I'm enjoying a short vacation so I cannot try your example: I will do once
I get back.
|
As the related issue is now closed, I will try to get at this soon. |
The parse error is now fixed in just released v3.6, but I'm leaving this open to remind me a possible clarification in the doc about other issues:
|
@lelit I am confused here as well, when to use either of the two. Can you please clarify. |
I will try to clarify this in the documentation. Consider the following examples: they parse the same from pprint import pprint
from pglast import parse_plpgsql
STMT = """\
CREATE FUNCTION add (a integer, b integer)
RETURNS integer AS $$
BEGIN
RETURN a + b;
END;
$$ LANGUAGE plpgsql
"""
as_plpgsql = parse_sql(STMT)
pprint(as_plpgsql) This prints out
that, as you can see, is just a list of plain Python dictionaries. If you use from pprint import pprint
from pglast import parse_sql
STMT = """\
CREATE FUNCTION add (a integer, b integer)
RETURNS integer AS $$
BEGIN
RETURN a + b;
END;
$$ LANGUAGE plpgsql
"""
as_sql = parse_sql(STMT)
pprint([stmt(skip_none=True) for stmt in as_sql]) This emits
The |
Hello! Nice projection! Trying to determine if this library could be utilized to parse many SQL statements to form an AST of a schema - or at least have the per-statement AST parsed in useful ways to formulate things about the schema. I am uncertain of the difference between the
parse_sql
andparse_plpgsql
functions and how to utilize them correctly. An example...Using
parse_plpgsql
fails:Using
parse_sql
here works, but yields a big blob unparsed:Trying to parse that inner blob as plpgsql similarly does not work:
Any tips?
Further - any heuristic to not need to explicitly declare "this function should be parsed as SQL" versus "this function should be parsed as PL/pgSQL", or do I need to decide that per statement?
The text was updated successfully, but these errors were encountered: