Skip to content

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

License

Notifications You must be signed in to change notification settings

davidjmerriman/queryparser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation

queryparser

Prerequisites

Windows

Once you've installed git and mingw, you need to make mingw aware of your filesystem and the location of git.

  • Open C:/MinGW/msys/1.0/etc/fstab (create if it doesn't exist), and add:
C:\MinGW    /mingw
C:\         /c
  • Open C:/MinGW/msys/1.0/home/<username>/.profile (create if it doesn't exist), and add:
PATH="/c/Program Files/Git/cmd:${PATH}"

Now, when running the commands for building, you will launch C:\MinGW\msys\1.0\msys.bat, and run them from there.

Linux

Install instructions for Ubuntu; may vary if your distro uses yum, rpm, etc. instead of apt-get

  • git sudo apt-get install git
  • gcc sudo apt-get install gcc
  • bison sudo apt-get install bison
  • flex sudo apt-get install flex

OS X

TODO

Installation

# Checkout repo
git clone https://github.com/davidjmerriman/queryparser.git queryparser
cd queryparser

# Build Queryparser binary
./build.sh

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

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

This repository was forked from queryparser, which was created by:

License

Copyright (c) 2015, David Merriman [email protected]
Copyright (c) 2014, pganalyze Team [email protected]
queryparser is licensed under the 3-clause BSD license, see LICENSE file for details.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 50.3%
  • Shell 49.7%