PostgresSQL psql 雜項指令
與 psql 相關雜七雜八指令
下述 postgres psql 指定,都有相似的 postgres sql 指令可達到。 不確定其他 DB 是否有相似功能...
列出指定 Table 的詳細資訊:\dt+
-
\dt+
\d
: describe, displayt
: table,僅列出 table 層級的資訊。+
: 顯示額外資訊,如 size、Description 等
- 可得到: Schema、Table Name、Type、Owner、Size、Description、Persistence 等。可能因版本而有差異。
- Persistence: permanent / temporary / unlogged
查單一 table 資訊
-
\dt+
totem=> \dt+ tablename
列出指定 table 下 columns 的詳細資訊:\d+
查 table 下 columns 資訊
\d+
: 省略 t 參數,則可顯示 columns 相關資訊。- 會列出所有 columns 型別屬性等
- FK、index 等
totem=> \d+ tablename
列出 schema 詳細資訊:\dt+
查整個 schema 中 table 層級資訊
totem=> \dt+ public.*
查整個 schema 中所有資訊
- 同樣略 t 參數,則會列出更詳細到 columns 的細節。
- 包含: PK、FK、sequence、index 與 index 種類、Table relations 、
totem=> \d+ public.*
列出 database 下所有 functions:\df
- 指令與列出 table 資訊相似,將 t (tables) 參數改成 f(functions) 變成查 functions
\df
: 查詢 databas 下的自訂 functions- \df 相關指令與參數變化
- 指令
\df
: 列出自訂函式的基本資訊。\dfS
: 限定列出 系統 函式的基本資訊。\df+
: 列出自訂函式的詳細資訊。會列出 function 原始碼。\df[a|n|t|w]
: 列出特定 types 類型且符合模式的函式。\ef [function_name]
: 顯示 function 原始碼,並允許編輯。
- 參數
- Pattern:
\df [pattern]
: 列出相似名稱的 functions。 - Schema:
\df [schema_name].*
: 限定指定 schema 下 functions。
- Pattern:
- Types: 函式的類型
- a: Aggregate functions
- t: Trigger functions
- w: Window functions
- n: Normal functions (排除 atw 類)
- 指令