This repository provides a Python SQL string parser.
Project description
SQL Parser
This package convert SQL string into a syntax tree object.
These objects can then be manipulated via Python's code.
The SQL syntax used is the one used by Apache Spark, based on Presto's one.
It is defined in src/sqlparser/grammar/SqlBase.g4.
Usage
from sqlparser import parse_statement
from sqlparser.utils import print_tree
tree = parse_statement('SELECT * FROM table WHERE column LIKE "%Python%"')
print_tree(tree)
Result (each line is a node of the tree):
|SingleStatementContext
|-StatementDefaultContext
|--QueryContext
|---QueryTermDefaultContext
|----QueryPrimaryDefaultContext
|-----RegularQuerySpecificationContext
|------SelectClauseContext
|-------TerminalNodeImpl[SELECT]
|-------NamedExpressionSeqContext
|--------NamedExpressionContext
|---------ExpressionContext
|----------PredicatedContext
|-----------ValueExpressionDefaultContext
|------------StarContext
|-------------TerminalNodeImpl[*]
|------FromClauseContext
|-------TerminalNodeImpl[FROM]
|-------RelationContext
|--------TableNameContext
|---------MultipartIdentifierContext
|----------ErrorCapturingIdentifierContext
|-----------IdentifierContext
|------------UnquotedIdentifierContext
|-------------NonReservedContext
|--------------TerminalNodeImpl[table]
|-----------RealIdentContext
|---------TableAliasContext
|------WhereClauseContext
|-------TerminalNodeImpl[WHERE]
|-------PredicatedContext
|--------ValueExpressionDefaultContext
|---------ColumnReferenceContext
|----------IdentifierContext
|-----------UnquotedIdentifierContext
|------------NonReservedContext
|-------------TerminalNodeImpl[column]
|--------PredicateContext
|---------TerminalNodeImpl[LIKE]
|---------ValueExpressionDefaultContext
|----------ConstantDefaultContext
|-----------StringLiteralContext
|------------TerminalNodeImpl["%Python%"]
|---QueryOrganizationContext
|-TerminalNodeImpl[<EOF>]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pythonsqlparser-0.1.2.tar.gz
(143.7 kB
view hashes)
Built Distribution
Close
Hashes for pythonsqlparser-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dee61eeacb2c37174b565dee9c9dc6060af85e3382ba024b285b22b21dc55a74 |
|
MD5 | d6b6397ee8c3c2970ce6cc22dd751cc4 |
|
BLAKE2b-256 | a315972df06d101b84c2e9505aa6f53eea8f276b79270e5657370eb68c05e4a8 |