-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please give some example!!! #10
Comments
Hi @weiboyiyou, You would need to use a type assertion to check for the type of node thats contained in the list. I don't have a good example handy right now, though I can try writing one later this week, let me know if helpful. If you are looking for a more approachable API, the Ruby library is better documented and easier to use for simple use cases: https://github.com/lfittl/pg_query Best, |
Hi,@lfittl, |
@weiboyiyou are you still looking for examples? |
@elliotcourant a few examples would be pretty helpful |
The lack of examples really makes it complicated to understand how to work with the parsed struct objects. I've been just trying all the methods in the |
@camilovietnam You may find it helpful to look at the Postgres source code directly - all that that pg_query does is package the Postgres internal AST structs in a way that makes them accessible outside the server itself. For example, regarding the default value: https://github.com/postgres/postgres/blob/master/src/include/nodes/parsenodes.h#L695 All the Go code does is transform that into actual structs - if you search for "ColumnDef" in the protobuf generated code you'll find the relevant parts: https://raw.githubusercontent.com/pganalyze/pg_query_go/main/pg_query.pb.go There is also auto-generated documentation that may be a bit easier to read: https://pkg.go.dev/github.com/pganalyze/pg_query_go/v2#ColumnDef |
For the authors of this library - this is such a useful library, thank you! I do agree with the need for some useful examples, despite the fact that this library simply exposes some PG internals, for the reason that this library would serve as the API for potential users. Thus, this is where people expect to find such examples. I also think that some examples here would go a long long way towards more widespread adoption of the library, assuming lack of examples coupled with relative complexity of the API serves as the biggest potential barrier for adoption here (few people are familiar with internal PG ASTs...) Some ideas for examples:
These are use-cases I see every-day and can be useful in a variety of contexts. Regardless, thanks again for writing this! |
Hi,
please give me some how to use pg_query_go,like pg_query.Parse ,when I get the ParsetreeList , how can i get where the sql is select or update ?
The text was updated successfully, but these errors were encountered: