PostgreSQL顯示全部資料庫的方式如下。
在psql命令列輸入\list或縮寫\l可列出所有的資料庫。例如目前我的PostgreSQL有三個databases postgres、template0、template1。
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+---------+-------+-------------------
postgres | user | UTF8 | C | C |
template0 | user | UTF8 | C | C | =c/user +
| | | | | user=CTc/user
template1 | user | UTF8 | C | C | =c/user +
| | | | | user=CTc/user
(3 rows)
或使用SELECT datname FROM pg_database;查詢全部的資料庫名稱。
postgres=# SELECT datname FROM pg_database;
datname
-----------
postgres
template1
template0
(3 rows)
查詢目前所在的資料庫可查詢current_catalog或current_database()。例如下面顯示目前的資料庫為postgres
postgres=# SELECT current_catalog;
current_catalog
-----------------
postgres
(1 row)
postgres=# SELECT current_database();
current_database
------------------
postgres
(1 row)
沒有留言:
張貼留言