PostgreSQL – How to Find the Owner of a Table
To find the owner of a table in PostgreSQL, you can use the following SQL query:
SELECT tablename, tableowner FROM pg_catalog.pg_tables WHERE schemaname = 'my_schema' AND tablename = 'your_table_name';
where 'my_schema'
is the name of the schema where your table resides, and 'your_table_name'
is the name of the table you want to find the owner for.
Here’s how the query works:
- It queries the
pg_catalog.pg_tables
view, which contains metadata about tables in the database. - It filters the results based on the
schemaname
andtablename
columns. In the query above, it’s looking for a table with the specified schema and table name. - It selects the
tablename
andtableowner
columns, which will give you the name of the table and the owner of that table.
After executing this query, you will get the name of the table along with its owner.