Skip to main content

PyPI Latest Release License Travis Build Status

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>]

Release files for pythonsqlparser 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pythonsqlparser 0.1.2
File Size Uploaded
pythonsqlparser-0.1.2.tar.gz 143.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pythonsqlparser 0.1.2
File Interpreter ABI Platform
pythonsqlparser-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 290.9 kB

Release files / pythonsqlparser-0.1.2.tar.gz

Download URL pythonsqlparser-0.1.2.tar.gz
Size 143.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b4d977d990d3b958deeecf88990c1005a6fd7e50a9c811fad7d97d8e3646c1b3
BLAKE2b-256 checksum
How to use checksums
3ba3524a56163ab6fdd5f608c14e03b586f05ec0cdc35a90af9becba63aa8a8d
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pythonsqlparser-0.1.2-py3-none-any.whl

Download URL pythonsqlparser-0.1.2-py3-none-any.whl
Size 147.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dee61eeacb2c37174b565dee9c9dc6060af85e3382ba024b285b22b21dc55a74
BLAKE2b-256 checksum
How to use checksums
a315972df06d101b84c2e9505aa6f53eea8f276b79270e5657370eb68c05e4a8
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page