{"id":13590590,"url":"https://github.com/auxten/postgresql-parser","last_synced_at":"2025-04-04T14:06:04.987Z","repository":{"id":42390417,"uuid":"339098424","full_name":"auxten/postgresql-parser","owner":"auxten","description":"Pure Golang PostgreSQL (SQL:2011, SQL:2008, SQL:2003, SQL:1999, and SQL-92 Standard) Parser","archived":false,"fork":false,"pushed_at":"2024-06-04T06:52:58.000Z","size":5469,"stargazers_count":282,"open_issues_count":6,"forks_count":56,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-28T13:05:39.794Z","etag":null,"topics":["cockroachdb","golang","postgresql","sql","sql-parser","sql2011"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/auxten.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-15T14:11:26.000Z","updated_at":"2025-03-15T22:18:16.000Z","dependencies_parsed_at":"2024-06-18T13:51:01.101Z","dependency_job_id":"b1c6f707-f14e-4fc7-ba84-eef9750fc59a","html_url":"https://github.com/auxten/postgresql-parser","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auxten%2Fpostgresql-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auxten%2Fpostgresql-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auxten%2Fpostgresql-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auxten%2Fpostgresql-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/auxten","download_url":"https://codeload.github.com/auxten/postgresql-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247186629,"owners_count":20898187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cockroachdb","golang","postgresql","sql","sql-parser","sql2011"],"created_at":"2024-08-01T16:00:48.479Z","updated_at":"2025-04-04T14:06:04.965Z","avatar_url":"https://github.com/auxten.png","language":"Go","readme":"# What's this\nPostgreSQL style Parser splitted from [CockroachDB](https://github.com/cockroachdb/cockroach)\n\nSee: [Complex SQL format example](example/format/format.go)\n\nI tried to import `github.com/cockroachdb/cockroach/pkg/sql/parser`, but the dependencies is too complex to make it work. \n\nTo make things easy, I did these things:\n\n1. Copy all the `pkg/sql/parser`, `pkg/sql/lex` and simplify the dependencies\n2. Simplify the Makefile to just generate the goyacc stuff\n3. Add the goyacc generated files in parser and lex to make `go get` work easily, see the `.gitignore` files\n4. Trim the `etcd` dependency, see the `go.mod`\n5. Rename all test file except some `pkg/sql/parser` tests\n6. Add all necessary imports to vendor\n7. Remove the `panic` of meeting unregistried functions, see the [WrapFunction](pkg/sql/sem/tree/function_name.go#L67)\n8. Other nasty things make the parser just work that I forgot :p\n\n# Who is using this\n\n- [Atlas](https://github.com/ariga/atlas) 1.8k stars\n- [ByteBase](https://github.com/bytebase/bytebase) 3.6k stars\n- [More](https://github.com/auxten/postgresql-parser/network/dependents)\n\n# Features\n- Pure golang implementation\n- *Almost* full support of PostgreSQL (`cockroachdb` style PostgreSQL)\n- For SQL lineage analysis see [go-sql-lineage](https://github.com/auxten/go-sql-lineage)\n\n## SQL Standard Compliance\n\nThe code is derived from CockroachDB v20.1.11 which supports most of the major features of SQL:2011. See:\n\n- https://www.cockroachlabs.com/docs/v20.1/postgresql-compatibility\n\n- https://www.postgresql.org/docs/9.5/features.html\n\n# How to use\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\n\t\"github.com/auxten/postgresql-parser/pkg/sql/parser\"\n\t\"github.com/auxten/postgresql-parser/pkg/walk\"\n)\n\nfunc main() {\n\tsql := `select marr\n\t\t\tfrom (select marr_stat_cd AS marr, label AS l\n\t\t\t\t  from root_loan_mock_v4\n\t\t\t\t  order by root_loan_mock_v4.age desc, l desc\n\t\t\t\t  limit 5) as v4\n\t\t\tLIMIT 1;`\n\tw := \u0026walk.AstWalker{\n\t\tFn: func(ctx interface{}, node interface{}) (stop bool) {\n\t\t\tlog.Printf(\"node type %T\", node)\n\t\t\treturn false\n\t\t},\n\t}\n\t\n\tstmts, err := parser.Parse(sql)\n\tif err != nil {\n\t\treturn\n\t}\n\t\n\t_, _ = w.Walk(stmts, nil)\n\treturn\n}\n\n```\n\n# SQL parser\n\nThis project contains code that is automatically generated using `goyacc`.\n`goyacc` reads the SQL expressions ([`sql.y`](https://github.com/auxten/postgresql-parser/blob/main/pkg/sql/parser/sql.y)) and generates a parser which could be used to tokenize a given input.\nYou could update the generated code using the `generate` target inside the project's Makefile.\n\n```bash\n$ make generate\n```\n\n# Progress\n- 2021-02-16 `github.com/auxten/postgresql-parser/pkg/sql/parser` Unit tests works now!\n- 2021-03-08 Add walker package.\n- 2022-08-03 Remove vendored dependencies by @mostafa in https://github.com/auxten/postgresql-parser/pull/19\n\n# Todo\n- Fix more unit tests\n- Make built-in function parsing work\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauxten%2Fpostgresql-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauxten%2Fpostgresql-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauxten%2Fpostgresql-parser/lists"}