/queryparser

Interface to PostgreSQL's query parser, for turning SQL into a parse tree.

Primary LanguageCBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

queryparser

Installation

To get things running, run the following in a checkout of this repo:

# Build PostgreSQL
git clone --depth 1 https://github.com/pganalyze/postgres.git postgresql

cd postgresql
./configure
make
cd ..

# Build Queryparser binary
./build.sh

The built queryparser binary is standalone and works without any PostgreSQL libraries existing or server running.

Note: We use a patched version of PostgreSQL, with improvements to outfuncs.c.

Usage

# Parse a query into Postgres' internal format
echo 'SELECT 1' | ./queryparser

# ({SELECT :distinctClause <> :intoClause <> :targetList ({RESTARGET :name <> :indirection <> :val {A_CONST :val 1 :location 7} :location 7}) :fromClause <> :whereClause <> :groupClause <> :havingClause <> :windowClause <> :valuesLists <> :sortClause <> :limitOffset <> :limitCount <> :lockingClause <> :withClause <> :op 0 :all false :larg <> :rarg <>})

# Parse a query into JSON
echo 'SELECT 1' | ./queryparser --json

# [{"SELECT": {"distinctClause": null, "intoClause": null, "targetList": [{"RESTARGET": {"name": null, "indirection": null, "val": {"A_CONST": {"val": 1, "location": 7}}, "location": 7}}], "fromClause": null, "whereClause": null, "groupClause": null, "havingClause": null, "windowClause": null, "valuesLists": null, "sortClause": null, "limitOffset": null, "limitCount": null, "lockingClause": null, "withClause": null, "op": 0, "all": false, "larg": null, "rarg": null}}]

Contributors

License

Copyright (c) 2014, pganalyze Team team@pganalyze.com
queryparser is licensed under the 3-clause BSD license, see LICENSE file for details.