首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >遍历模式

遍历模式
EN

Stack Overflow用户
提问于 2021-07-27 03:51:51
回答 1查看 85关注 0票数 0

我的数据库中有几个模式。大多数模式都有一个名为orders的表。如何迭代具有该表的模式,并为该表获取每个模式中记录的数量?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-27 04:40:31

select * from information_schema.schemata;

请参阅https://www.postgresql.org/docs/11/infoschema-schemata.html

代码语言:javascript
复制
do
$$
declare
    tableName varchar := 'xyz';
    schemaName varchar;
    query text;
    counter integer;
begin
    for schemaName in select table_schema from information_schema.tables where table_name = tableName
        loop
            query := 'select count(*) from ' || schemaName || '.' || tableName;
            execute query into counter;
            raise notice E'%  %', schemaName, counter;
        end loop ;

end $$
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68538740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档