添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
开朗的茄子  ·  Spark - RCC User Guide·  2 天前    · 
儒雅的豌豆  ·  python 类 属性 ...·  18 小时前    · 
爽快的花卷  ·  3. Python 风格规范 - ...·  12 小时前    · 
愤怒的豆芽  ·  Please, help to ...·  1 月前    · 
坏坏的红茶  ·  Mac ...·  1 月前    · 
不羁的硬盘  ·  Uninstall the Brother ...·  2 月前    · 

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.

Download files

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

Source Distribution Hashes for python_sqlparser-1.2-cp36-cp36m-win_amd64.whl Hashes for python_sqlparser-1.2-cp36-cp36m-win_amd64.whl Algorithm Hash digest "PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2024 Python Software Foundation
Site map