pg_query
pg_query copied to clipboard
Picking out the column names from a select statement
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!