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 details)
Built Distribution
File details
Details for the file pythonsqlparser-0.1.2.tar.gz
.
File metadata
- Download URL: pythonsqlparser-0.1.2.tar.gz
- Upload date:
- Size: 143.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
b4d977d990d3b958deeecf88990c1005a6fd7e50a9c811fad7d97d8e3646c1b3
|
|
MD5 |
6bffe145f40e2d0d66181017fc4d7f10
|
|
BLAKE2b-256 |
3ba3524a56163ab6fdd5f608c14e03b586f05ec0cdc35a90af9becba63aa8a8d
|
File details
Details for the file pythonsqlparser-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: pythonsqlparser-0.1.2-py3-none-any.whl
- Upload date:
- Size: 147.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
dee61eeacb2c37174b565dee9c9dc6060af85e3382ba024b285b22b21dc55a74
|
|
MD5 |
d6b6397ee8c3c2970ce6cc22dd751cc4
|
|
BLAKE2b-256 |
a315972df06d101b84c2e9505aa6f53eea8f276b79270e5657370eb68c05e4a8
|