What columns are needed to list the database, schema and table a record comes from?
0
votes
2
answers
122
views
I am writing queries which read identical tables across databases and schemas and I need the columns to include which schema and table a row comes from.
While searching during the creation of this post I came across [this answer](https://stackoverflow.com/a/20576324)
SELECT u.*, n.nspname as schema, u.tableoid::regclass::text as table_or_view
FROM uses u
JOIN pg_class c ON c.oid = u.tableoid
JOIN pg_namespace n ON c.relnamespace = n.oid
This now includes the schema and the table or view.
What joins do I need now to add the database as well?
Asked by vfclists
(1093 rep)
Feb 5, 2023, 12:06 PM
Last activity: Feb 6, 2023, 02:05 PM
Last activity: Feb 6, 2023, 02:05 PM