在PostgreSQL中导出/查询数据库表的最新记录

问题描述 投票:0回答:1

我想查询一个数据库,该数据库将从PostgreSQL中的数据库中选择schema_name,max(date_column),table_name。

有没有可以实现上述方案的过程?

谢谢。

postgresql pgadmin greenplum
1个回答
0
投票
select table_schema, table_name, (xpath( '/row/max/text()', query_to_xml(format('select max(%I) from %I.%I', column_name, table_schema, table_name), true, true, '') ) )[1]::text::int as max_value from information_schema.columns where table_schema = 'public' --<< adjust for your schema name(s) and column_name = 'date_column' --<< adjust for the real name of your column
© www.soinside.com 2019 - 2024. All rights reserved.