auxten / postgresql-parser

Pure Golang PostgreSQL (SQL:2011, SQL:2008, SQL:2003, SQL:1999, and SQL-92 Standard) Parser
Apache License 2.0
273 stars 50 forks source link

How do I parse a given sql statement, and add where / order by / lilmit clauses to it? #25

Closed vamshiaruru32 closed 1 year ago

vamshiaruru32 commented 1 year ago

Hi! I am total beginner to this library and am unable to figure out how to add a where clause to a select statement. Is this library only meant for parsing and getting a tree, but not adding anything to that tree? Any help is appreciated, thank you.

auxten commented 1 year ago

Modifying the SQL AST is also ok. You can modify the AST and convert it to String.

auxten commented 1 year ago

Set a breakpoint after parsing SQL, and check the AST structure will help you understand how to modify it. There is a relatively complex example of modifying the AST. https://github.com/auxten/go-sql-lineage/blob/main/lineage/normalize.go#L32