PostgreSQL 13で現在のデータベース名を取得する

環境
PostgreSQL 13.2
Windows 10 64bit

方法1
select current_catalog
使用例
SQL構文
select current_catalog result;
実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
testdb=# select current_catalog result;
result
--------
testdb
(1)
testdb=# select current_catalog result; result -------- testdb (1 行)
testdb=# select current_catalog result;
 result
--------
 testdb
(1 行)

方法2
select current_database()
使用例
SQL構文
select current_database() result;
実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
testdb=# select current_database() result;
result
--------
testdb
(1)
testdb=# select current_database() result; result -------- testdb (1 行)
testdb=# select current_database() result;
 result
--------
 testdb
(1 行)

 

PostgreSQL

Posted by arkgame