KonnexionsGmbH / sqlparse

LALR grammar based SQL Parser
Other
43 stars 15 forks source link

CREATE VIEW statement: Fix contradictions between sqlparse and Oracle syntax #83

Closed walter-weinmann closed 6 years ago

walter-weinmann commented 7 years ago

This solves the issues #24. The new grammar definition is not parse tree compatible with the existing grammar.


Oracle 12c grammar (simplified):

Oracle Database SQL Language Reference

create_view::= image

subquery_restriction_clause::= image


Current sqlparse grammar:

view_def -> CREATE VIEW table                                                                   : {'create view', '$3', []}.
view_def -> CREATE VIEW table '(' column_commalist ')'                                          : {'create view', '$3', '$5'}.
view_def -> AS query_spec                                                                       : {as, '$2', []                 }.
view_def -> AS query_spec WITH CHECK OPTION                                                     : {as, '$2', "with check option"}.

New sqlparse grammar:

view_def -> CREATE VIEW table                          AS query_spec                            : {'create view', '$3', [],   {as, '$5', []}}.
view_def -> CREATE VIEW table                          AS query_spec WITH CHECK OPTION          : {'create view', '$3', [],   {as, '$5', "with check option"}}.
view_def -> CREATE VIEW table '(' column_commalist ')' AS query_spec                            : {'create view', '$3', '$5', {as, '$8', []}}.
view_def -> CREATE VIEW table '(' column_commalist ')' AS query_spec WITH CHECK OPTION          : {'create view', '$3', '$5', {as, '$8', "with check option"}}.
walter-weinmann commented 6 years ago

Solved with PR #103.