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

Picking out the column names from a select statement #279

Open
skcuslleb opened this issue Mar 1, 2023 · 1 comment
Open

Picking out the column names from a select statement #279

skcuslleb opened this issue Mar 1, 2023 · 1 comment
Labels

Comments

@skcuslleb
Copy link

Hi there,

I can't quite figure out if it's possible to determine the column names returned by a select statement. I think I've narrowed it down to:
a) If there's an alias I use
parsed.tree.stmts[0].stmt.select_stmt.target_list[<x>].res_target.name
b) If there no alias I can use
parsed.tree.stmts[0].stmt.select_stmt.target_list[<x>].res_target.val.column_ref.fields.last.string.sval

Is this the best way to achieve this? I think it works, but it seems incredibly clunky... is there an analog for the filter_columns method that would do the same thing?

Thanks!

@lfittl
Copy link
Member

lfittl commented Mar 24, 2023

@skcuslleb There is no helper that gets the target list column names today - but certainly open to adding one, similar to filter columns. A PR to discuss further would be welcome!

Note that if your goal is to match what Postgres would output this would only work in some cases, as for example, pg_query does not have enough information to resolve "SELECT * FROM table" to a list of the table's column names.

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