Skip to content
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

WISHLIST: Expose pg_query_nodes_to_json() #107

Open
mdr1384 opened this issue May 12, 2021 · 2 comments
Open

WISHLIST: Expose pg_query_nodes_to_json() #107

mdr1384 opened this issue May 12, 2021 · 2 comments

Comments

@mdr1384
Copy link

mdr1384 commented May 12, 2021

WISHLIST ITEM:

It would be very nice if you could expose pg_query_nodes_to_json() so that we can convert existing trees to JSON.

E.g. I can get the necessary query tree directly from Postgres via the pg_catalog:

psql -At -U superuser -d testdb -c "select r.ev_action from pg_catalog.pg_rewrite r left join pg_catalog.pg_class c on r.ev_class = c.oid where c.relname = 'my_sick_view'" > /tmp/my_sick_view.qtree

In my case this results in a file over 180KB.

Now it would be nice to be able to write a simple program to convert it to JSON using pg_query_nodes_to_json(), but it is not in the public header.

@lfittl
Copy link
Member

lfittl commented May 24, 2021

@mdr1384 I think that sounds reasonable - if I understand correctly you would also need a way to go from the built-in node text format (the one thats very obscure and hard to read) to in-memory structs, correct?

Or were you thinking of using this as an extension in a running Postgres server? (then you'd only need access to the function you mention)

@mdr1384
Copy link
Author

mdr1384 commented May 28, 2021

I was not thinking that anything special needed to be running on the server. Just a way to get the JSON query tree for a given PostgreSQL query tree. Don't need in-memory structs either, there are already libs that convert the JSON string to structs.

FYI my reasoning was that converting the SQL schema definition as in your basic example was failing for me due to the extreme complexity of the schema (a VIEW with about 70 columns and many JOINs and function calls and a couple WITH clauses.) So I figured let PostgreSQL do the SQL parsing and then all I need is to convert PostgreSQL query tree language to JSON. I saw there was a function to do that but it was not public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants