- Notifications
You must be signed in to change notification settings - Fork59
Pure Golang PostgreSQL (SQL:2011, SQL:2008, SQL:2003, SQL:1999, and SQL-92 Standard) Parser
License
auxten/postgresql-parser
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
PostgreSQL style Parser splitted fromCockroachDB
See:Complex SQL format example
I tried to importgithub.com/cockroachdb/cockroach/pkg/sql/parser, but the dependencies is too complex to make it work.
To make things easy, I did these things:
- Copy all the
pkg/sql/parser,pkg/sql/lexand simplify the dependencies - Simplify the Makefile to just generate the goyacc stuff
- Add the goyacc generated files in parser and lex to make
go getwork easily, see the.gitignorefiles - Trim the
etcddependency, see thego.mod - Rename all test file except some
pkg/sql/parsertests - Add all necessary imports to vendor
- Remove the
panicof meeting unregistried functions, see theWrapFunction - Other nasty things make the parser just work that I forgot :p
- Pure golang implementation
- Almost full support of PostgreSQL (
cockroachdbstyle PostgreSQL) - For SQL lineage analysis seego-sql-lineage
The code is derived from CockroachDB v20.1.11 which supports most of the major features of SQL:2011. See:
package mainimport ("log""github.com/auxten/postgresql-parser/pkg/sql/parser""github.com/auxten/postgresql-parser/pkg/walk")funcmain() {sql:=`select marrfrom (select marr_stat_cd AS marr, label AS l from root_loan_mock_v4 order by root_loan_mock_v4.age desc, l desc limit 5) as v4LIMIT 1;`w:=&walk.AstWalker{Fn:func(ctxinterface{},nodeinterface{}) (stopbool) {log.Printf("node type %T",node)returnfalse},}stmts,err:=parser.Parse(sql)iferr!=nil {return}_,_=w.Walk(stmts,nil)return}
This project contains code that is automatically generated usinggoyacc.goyacc reads the SQL expressions (sql.y) and generates a parser which could be used to tokenize a given input.You could update the generated code using thegenerate target inside the project's Makefile.
$ make generate
- 2021-02-16
github.com/auxten/postgresql-parser/pkg/sql/parserUnit tests works now! - 2021-03-08 Add walker package.
- 2022-08-03 Remove vendored dependencies by @mostafa in#19
- Fix more unit tests
- Make built-in function parsing work
About
Pure Golang PostgreSQL (SQL:2011, SQL:2008, SQL:2003, SQL:1999, and SQL-92 Standard) Parser
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.