【发布时间】:2019-01-27 04:44:28
【问题描述】:
如何查询数据库中所有表的所有表列?
我试过的方法:
- 使用
select tablename from pg_tables where schemaname = 'public'获取所有表名 - 使用 Postgres 的
UNION方法处理 cmd 字符串。 - 执行 cmd 字符串。
我在数据库中有 19 个表,我的方法导致查询时间慢了 19 倍。而且,它不会返回我想要的。所有表都有两列,其中一列始终是名为time 的列名。使用UNION 方法不会返回19 个time 字符串。它只返回一个time 字符串和其他19 个列名。但我想要这样的东西:
[('table_1', ['time', 'col']), ('table_2', ['time', 'col']), ('table_3', ['time', 'col])...].
有什么优雅的方法吗?
【问题讨论】:
标签: python sql arrays database postgresql