Postgres DB 内のすべてのテーブルを一覧表示するクエリはありますか?
次のようなクエリを 1 つ試しました。
SELECT table_name FROM information_schema.tables
WHERE table_schema='public'
ただし、このクエリはビューも返します。
ビューではなく、テーブル名のみを取得するにはどうすればよいですか?
Postgres DB 内のすべてのテーブルを一覧表示するクエリはありますか?
次のようなクエリを 1 つ試しました。
SELECT table_name FROM information_schema.tables
WHERE table_schema='public'
ただし、このクエリはビューも返します。
ビューではなく、テーブル名のみを取得するにはどうすればよいですか?
このクエリは(マニュアルの説明に基づいて)どのようになりますか?
SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
AND table_type='BASE TABLE';
データベースの一覧が欲しい場合
SELECT datname FROM pg_database WHERE datistemplate = false;
すべてのデータベースの現在の pg インストールからのテーブルのリストが必要な場合
SELECT table_schema,table_name FROM information_schema.tables
ORDER BY table_schema,table_name;
select
relname as table
from
pg_stat_user_tables
where schemaname = 'public'
select
tablename as table
from
pg_tables
where schemaname = 'public'