[英]postgres count tables in db
I want to get the count of tables inside the 'hgp17290_data' db in pgadmin. 我想在pgadmin中获取'hgp17290_data'db内的表的数量。 I've been messing about with POSTGRES SQL and I can get the size of a db, like so:
我一直在搞乱POSTGRES SQL,我可以得到db的大小,如下所示:
select pg_database_size('hgp17290_data');
but I cant get the number of tables in this db, the below examples I couldnt get going 但我无法得到这个数据库中的表数,下面的例子我无法进行
SELECT
pg_database.datname,
pg_size_pretty(pg_database_size(pg_database.datname)) AS size
FROM pg_database;
SELECT pg_size_pretty( pg_total_relation_size('DemoLayer1'));
select count(*)
from information_schema.tables
where table_schema = 'hgp17290_data';
select * from pg_stat_user_tables ;
select count(*) from 'GeoAppBuilderData' ;
select * from pg_stat_all_tables ;
SELECT count(*) FROM GeoAppBuilderData.tables WHERE table_schema NOT IN ('GeoAppBuilderData', 'pg_catalog');
select pg_database_count('hgp17290_data');
select count(1) from ('hgp17290_data');
select 'hgp17290_data' db, 'users' 'hgp17290_data', count[1] "rowscount" from hgp17290_data.users
select table_schema,
table_name,
(xpath('/row/cnt/text()', xml_count))[1]::text::int as row_count
from (
select table_name, table_schema,
query_to_xml(format('select count(*) as cnt from %I.%I', table_schema, table_name), false, true, '') as xml_count
from information_schema.tables
where table_schema = 'hgp17290_data' --<< change here for the schema you want
SELECT COUNT(*) FROM ('hgp17290_data');
SELECT 'hgp17290_data' AS table_name, COUNT(*) FROM table_1
)
You've tried this query: 您已尝试过此查询:
select count(*)
from information_schema.tables
where table_schema = 'hgp17290_data';
But it seems to me, that you don't have to provide a where clause here with the schema name equals to your database name ( hgp17290_data
is your database name, not some schema name). 但在我看来,您不必在此处提供where子句,模式名称等于您的数据库名称(
hgp17290_data
是您的数据库名称,而不是某些模式名称)。 Try it simple as: 尝试简单:
select count(*)
from information_schema.tables;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.