# postgresql-parser **Repository Path**: shiqiyue/postgresql-parser ## Basic Information - **Project Name**: postgresql-parser - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-05-24 - **Last Updated**: 2021-11-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # What's this PostgreSQL style Parser splitted from [CockroachDB](https://github.com/cockroachdb/cockroach) See: [Complex SQL format example](example/format.go) I tried to import `github.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 the `pkg/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 make `go get` work easily, see the `.gitignore` files 4. Trim the `etcd` dependency, see the `go.mod` 5. Rename all test file except some `pkg/sql/parser` tests 6. Add all necessary imports to vendor 7. Remove the `panic` of meeting unregistried functions, see the [WrapFunction](pkg/sql/sem/tree/function_name.go#L67) 8. Other nasty things make the parser just work that I forgot :p # Features - Pure golang implementation - *Almost* full support of PostgreSQL (`cockroachdb` style PostgreSQL) ## SQL Standard Compliance The code is derived from CockroachDB v20.1.11 which supports most of the major features of SQL:2011. See: - https://www.cockroachlabs.com/docs/v20.1/postgresql-compatibility - https://www.postgresql.org/docs/9.5/features.html # How to use ```go package main import ( "log" "gitee.com/shiqiyue/postgresql-parser/pkg/walk" ) func main() { sql := `select marr from (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 v4 LIMIT 1;` w := &walk.AstWalker{ Fn: func(ctx interface{}, node interface{}) (stop bool) { log.Printf("node type %T", node) return false }, } _, _ = w.Walk(sql, nil) return } ``` ### 🚧🚧🚧 still under construction 🚧🚧🚧 # Progress - 2021-02-16 `gitee.com/shiqiyue/postgresql-parser/pkg/sql/parser` Unit tests works now! - 2021-03-08 Add walker package. # Todo - Fix more unit tests - Make built-in function parsing work