Skip to main content

A package for parsing SQL queries

Project description

python-sqlparser

A Python Module for the "General SQL Parser" library (sqlparser.com)

Refer

https://github.com/TwoLaid/python-sqlparser

Supported Systems

This library currently supports: Windows 32bit/64bit and Linux 32bit/64bit. There are currently no binaries for Mac OSX available.

This module support Python 2.* and Python 3.*

Installation

Simply clone or download this git and execute

pip install python-sqlparser

The setup script will automatically download the right library (from sqlparser.com) for you.

Usage

Simply import the module with import sqlparser The following example will parse a simple query:

import sqlparser

query = "SELECT a, b FROM table_1 WHERE c > 20"
# Init a oracle sql parser
parser = sqlparser.Parser(vendor=2)

# Check for syntax errors
if parser.check_syntax(query) == 0:
	# Get first statement from the query
	stmt = parser.get_statement(0)

	# Get root node
	root = stmt.get_root()

	print(root.__dict__)

And print the node information the SELECT node:

{"computeClause": None,
 "cteList": None,
 "expandOnClause": None,
 "fetchFirstClause": None,
 "forupdateClause": None,
 "fromTableList": <sqlparser.Node object at 0x7ff48c5eed50>,
 "groupByClause": None,
 "hierarchicalClause": None,
 "intoClause": None,
 "intoTableClause": None,
 "isolationClause": None,
 "leftNode": None,
 "limitClause": None,
 "lockingClause": None,
 "node_type": 5,
 "optimizeForClause": None,
 "orderbyClause": None,
 "qualifyClause": None,
 "resultColumnList": <sqlparser.Node object at 0x7ff48c5ee618>,
 "rightNode": None,
 "sampleClause": None,
 "selectDistinct": None,
 "selectToken": "SELECT",
 "setOperator": 0,
 "topClause": None,
 "valueClause": None,
 "whereCondition": <sqlparser.Node object at 0x7ff48c5eea78>,
 "windowClause": None,
 "withClauses": None}

Examples

For more examples please check the examples directory.

Project details


Release history Release notifications | RSS feed

This version

1.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-sqlparser-1.2.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

python_sqlparser-1.2-cp36-cp36m-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.6m Windows x86-64

File details

Details for the file python-sqlparser-1.2.tar.gz.

File metadata

  • Download URL: python-sqlparser-1.2.tar.gz
  • Upload date:
  • Size: 41.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.8

File hashes

Hashes for python-sqlparser-1.2.tar.gz
Algorithm Hash digest
SHA256 c0b21d1df44a02741a8b811a08e06163131fbbfca6b2fcb841724c71184a35e4
MD5 e3890f439dfbcf28168da9d469583117
BLAKE2b-256 7cae88d8b1b40e06575002960f45effdedf920fd8d96de55d866ffe87abcec04

See more details on using hashes here.

File details

Details for the file python_sqlparser-1.2-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: python_sqlparser-1.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.8

File hashes

Hashes for python_sqlparser-1.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 4f1e94d3b1287be1ffc77e9171f0cacc754a1696fa75bc7d87aa8d74f6e33b9a
MD5 09107a90c130986173e61c889a44c1a3
BLAKE2b-256 1b7b82174cc1cffca1dff4780699b71df97e6129a7ceb45f0e2c95c077fb07b9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page