How can I query all tables' all table columns in a database?
Method I've tried:
- get all table names using
select tablename from pg_tables where schemaname = 'public'
- Process cmd string using
UNION
method of Postgres. - Execute the cmd string.
I have 19 tables in a DB, and my method results in 19 times slower querying time. And further more, it does not return what I want. All of the tables have two columns, one of them always being a column name called time
. Using the UNION
method does not return 19 time
strings. It just returns one time
string, and 19 other column names. But I want something like this:
[('table_1', ['time', 'col']), ('table_2', ['time', 'col']), ('table_3', ['time', 'col])...]
.
Is there any elegant way of doing this?