Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pure Golang PostgreSQL (SQL:2011, SQL:2008, SQL:2003, SQL:1999, and SQL-92 Standard) Parser

License

NotificationsYou must be signed in to change notification settings

auxten/postgresql-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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:

  1. Copy all thepkg/sql/parser,pkg/sql/lex and simplify the dependencies
  2. Simplify the Makefile to just generate the goyacc stuff
  3. Add the goyacc generated files in parser and lex to makego get work easily, see the.gitignore files
  4. Trim theetcd dependency, see thego.mod
  5. Rename all test file except somepkg/sql/parser tests
  6. Add all necessary imports to vendor
  7. Remove thepanic of meeting unregistried functions, see theWrapFunction
  8. Other nasty things make the parser just work that I forgot :p

Who is using this

Features

  • Pure golang implementation
  • Almost full support of PostgreSQL (cockroachdb style PostgreSQL)
  • For SQL lineage analysis seego-sql-lineage

SQL Standard Compliance

The code is derived from CockroachDB v20.1.11 which supports most of the major features of SQL:2011. See:

How to use

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}

SQL parser

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

Progress

  • 2021-02-16github.com/auxten/postgresql-parser/pkg/sql/parser Unit tests works now!
  • 2021-03-08 Add walker package.
  • 2022-08-03 Remove vendored dependencies by @mostafa in#19

Todo

  • 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

Stars

Watchers

Forks

Packages

No packages published

Contributors5

Languages


[8]ページ先頭

©2009-2025 Movatter.jp