How can I get the label of each column in a result set to prepend the name if its table?
I want this to happen for queries on single tables as well as joins.
Example:
SELECT first_name, last_name FROM person;
I want the results to be:
| person.first_name | person.last_name |
|-------------------|------------------|
| Wendy | Melvoin |
| Lisa | Coleman |
I could use "AS" to define an alias for each column, but that would be tedious. I want this to happen automatically.
SELECT first_name AS person.first_name, last_name AS person.last_name FROM person;
The reason for my question is that I am using a database driver that does not provide the meta-data informing me the database column from where the result set got its data. I am trying to write generic code to handle the result set.
I would like to know how to do this in SQL generally, or at least in Postgres specifically.
SQLite had such a feature, though I see it is now inexplicably deprecated. SQLite has two pragma settings: full_column_names & short_column_names.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…