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

在postgresql中导出/查询数据库表的最新记录,postgresql,pgadmin,greenplum,Postgresql,Pgadmin,Greenplum,我想查询一个数据库,它将从PostgreSQL中的数据库中选择模式名称max(日期列)、表名称 是否有任何流程可以实现上述场景 谢谢。在Postgres中,您可以使用“”方法的变体: select table_schema, table_name, (xpath( '/row/max/text()', query_to_xml(format('select max(%I) from %I.%I', column_name, table_schema,

我想查询一个数据库,它将从PostgreSQL中的数据库中选择模式名称max(日期列)、表名称

是否有任何流程可以实现上述场景


谢谢。

在Postgres中,您可以使用“”方法的变体:

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
选择表格模式、表格名称、,
(xpath(“/row/max/text()”,
查询到xml(格式('select max(%I)from%I.%I',column\u name,table\u schema,table\u name),true,true,'))
)
)[1] ::text::int作为最大值
从信息_schema.columns

其中table_schema='public'--您好,我尝试了上面的查询,我只是在where条件下替换table_schema和column_name,我得到下面的错误:“error:function format(未知,信息\u schema.sql\u标识符,信息\u schema.sql\u标识符,信息\u schema.sql\u标识符)不存在第3行:查询到\u xml(格式('select max(%I)from%I.%…^提示:没有与给定名称和参数类型匹配的函数。您可能需要添加显式类型转换。”这适用于Postgres。您真正使用的是哪种数据库产品?是的,我只使用postgre(greenplum)greeplum还是Postgres?这是两种完全不同的数据库产品。greenplum是否支持
format()
query\u to\u xml()
?如果强制转换参数是否有效?
format(“..”,列\日期::文本,表\名称::文本,表\模式::文本)