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

What is the best way to check if a query uses a star? #294

Open
kduraiswami opened this issue Jul 5, 2023 · 1 comment
Open

What is the best way to check if a query uses a star? #294

kduraiswami opened this issue Jul 5, 2023 · 1 comment
Labels

Comments

@kduraiswami
Copy link

I am able to go all the way down into a query node like this

parsed_query.tree.stmts[0].stmt.select_stmt.target_list[0].res_target.val.column_ref.fields[0].respond_to?(:a_star)

but in ruby the method respond_to? is too loose because even if a query does not have a star in it the object itself does have this method.

Is this the most efficient way to traverse through the tree and ask if it has a star and try to access the property? Is there a risk this will return true even if it is not the case?

parsed_query.tree.stmts[0].stmt.select_stmt.target_list[0].res_target.val.column_ref.fields[0]["a_star"]

Thanks for the help, please let me know if I can clarify anything

@lfittl
Copy link
Member

lfittl commented Jul 5, 2023

You can use .node to check the type of the field:

parsed_query = PgQuery.parse("SELECT * FROM test")

parsed_query.tree.stmts[0].stmt.select_stmt.target_list[0].res_target.val.column_ref.fields[0].node
=> :a_star

@lfittl lfittl added the question label Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants