| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Note
pgplex: The Postgres Toolchain for Humans and Agents - pgconsole · pgschema · pgtui · pgparser
Brought to you by Bytebase, open-source database governance platform.
pgparser is a pure Go implementation of the PostgreSQL SQL parser. It translates the original PostgreSQL grammar (gram.y) into Go using goyacc, ensuring 100% compatibility with the PostgreSQL parse tree structure.
Target PostgreSQL Version: 17.7 (REL_17_STABLE)
go get github.com/pgplex/pgparserpackage main
import (
"encoding/json"
"fmt"
"log"
"github.com/pgplex/pgparser/parser"
)
func main() {
sql := "SELECT * FROM users WHERE id > 100"
// Parse the SQL string
stmts, err := parser.Parse(sql)
if err != nil {
log.Fatalf("Parse error: %v", err)
}
// Print the AST as JSON
jsonBytes, _ := json.MarshalIndent(stmts, "", " ")
fmt.Println(string(jsonBytes))
}This project is not a hand-written parser. It is a port of the official PostgreSQL source code:
# Regenerate parser (if gram.y changed)
make generate-parser
# Run tests
go test ./...
# Run PostgreSQL regression tests compatibility check
go test ./parser/pgregress -run TestPGRegressStats -vBytebase - open source, web-based database DevSecOps platform.
| Back | FazBrowse Home | New Git URL |