查询当前数据库用户表总数可用:SELECT count() AS table_count FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'pg_catalog') AND table_type = 'BASE TABLE'; 若要统计指定模式如public下的表,可使用:SELECT count() AS table_count FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE'; 也可通过pg_tables视图简化查询:SELECT count() AS table_count FROM pg_tables WHERE schemaname NOT IN ('information_schema', 'pg_catalog'); 或仅查public模式:SELECT count() AS table_count FROM pg_tables WHERE schemaname = 'public'; 推荐使用information_schema.tables或pg_tables,兼容性好且简洁清晰。

要查询一个 PostgreSQL 数据库中有多少张表,可以使用以下 SQL 语句:
查询当前数据库中所有用户表的数量
执行下面的查询,统计 当前数据库中所有用户创建的表(不包含系统表):
SELECT count(*) AS table_countFROM information_schema.tables
WHERE table_schema NOT IN ('information_schema', 'pg_catalog')
AND table_type = 'BASE TABLE';
这个查询会返回一个数字,表示当前数据库中用户表的总数。
只查指定模式(如 public)下的表数量
如果你只想统计某个模式(例如 public)下的表,可以加上 table_schema = 'public' 条件:
本版本采用三顾购物平台,适合应用于化妆品销售。一、商品管理 商品发布:支持4种自定义价格,自定义商品字段完美支持多种行业应用,商品显示属性控制,不限上传商品图片,每个商品均有5帧幻灯片支持,拥有新品、特价、推荐等属性,可自定义随意编写商品介绍。商品管理:按各种属性查看商品列表、库存及价格,管理具体商品。商品评论:管理审核删除回复网友对商品的评级及评论。另支持品牌管理、单位管理、赠品管理等。二、订单
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_type = 'BASE TABLE';
通过 pg_tables 查看(更简洁方式)
pg_tables 是 PostgreSQL 提供的一个系统视图,专门用于查看表信息。用它也可以快速统计:
SELECT count(*) AS table_countFROM pg_tables
WHERE schemaname NOT IN ('information_schema', 'pg_catalog');
或者只查 public 模式:
SELECT count(*) AS table_countFROM pg_tables
WHERE schemaname = 'public';
基本上就这些常用方法。推荐使用 information_schema.tables 或 pg_tables,它们清晰且兼容性好。









