「PostgreSQL」テーブル一覧を取得する方法

環境
Windows 10 Home 64bit
PostgreSQL 9.6.5

使用例
テーブル一覧をテーブル名順に取得します
方法1
SQL構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select
tablename
from
pg_tables
where
schemaname not in ('pg_catalog', 'information_schema')
order by
tablename;
select tablename from pg_tables where schemaname not in ('pg_catalog', 'information_schema') order by tablename;
select
  tablename 
from
  pg_tables 
where
  schemaname not in ('pg_catalog', 'information_schema') 
order by
  tablename;

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
tablename
-----------
address
infotbl
kdftbl
ktbl
tablename ----------- address infotbl kdftbl ktbl
 tablename
-----------
 address
 infotbl
 kdftbl
 ktbl

方法2
「\dt」コマンドで単にテーブルの一覧を取得します
書式
\dt
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# \dt
リレーションの一覧
スキーマ | 名前 || 所有者
----------+---------+----------+----------
public | address | テーブル | postgres
public | empp | テーブル | postgres
public | ktbl | テーブル | postgres
(3)
postgres=# \dt リレーションの一覧 スキーマ | 名前 | 型 | 所有者 ----------+---------+----------+---------- public | address | テーブル | postgres public | empp | テーブル | postgres public | ktbl | テーブル | postgres (3 行)
postgres=# \dt
            リレーションの一覧
 スキーマ |  名前   |    型    |  所有者
----------+---------+----------+----------
 public   | address | テーブル | postgres
 public   | empp    | テーブル | postgres
 public   | ktbl    | テーブル | postgres
(3 行)

 

PostgreSQL

Posted by arkgame