Closed aisbergde closed 3 years ago
maybe this should be implemented in sql_parser.py somthing like this 329
# SQL STATEMENT
selectColumn = Group(
Group(expr).setName("expression1")("value").setDebugActions(*debug) + Optional(Optional(AS) + ident.copy().setName("column_name1")("name").setDebugActions(*debug)) |
Group(expr).setName("column_name1")("name").setDebugActions(*debug) + Literal('=') + ident.copy().setName("expression1")("value").setDebugActions(*debug) |
Literal('*')("value").setDebugActions(*debug)
).setName("column").addParseAction(to_select_call)
I am not a python programmer but a database developer. But I like the way how this parser is programmed. The idea of this project is great and could help me to transform some manually defined views in a formalized presentation used in a repository, where each column of a view is represented as separate column in columns-table.
@aisbergde How does the parser distinguish between
A=B
(a comparison expression that returns a Boolean) andA=B
(rename column B as A
?I understand that this is not the job of the parser and need to be done outside. The idea was to get something like SSMS query designer which parses the query and brings it in a unique form. There are also some parsers which can detect the existence of an alias and combining the alias and the whole statement per column it can be transformed.
Some days ago I found a great solution for my goal: https://www.activequerybuilder.com/ has an undocumented web api to parse sql and I am allowed to use it for free for noncommercial purposes. It can't parse all possibilities (for example cross apply) but it parses most features which I need to transform a free text view definition in a unified form used by the www.analyticscreator.com repository to define views.
I need this kind of implementation. here is a test I prepared but because this is a feature request and not an error I am not sure if I should prepare a PR in the file test_simple.py
This is valid SQL in MSSQLSERVER TSQL and most of the views I need to parse are using this syntax:
here is a simple example of the kind of views I need to parse: