> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/reference/reference-client/app-psql/app-psql-patterns.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# psql：模式

[返回 psql 主頁](https://docs.postgresql.tw/19/reference/reference-client/app-psql.md)。

## 模式 [#](#app-psql-patterns) <a href="#app-psql-patterns" id="app-psql-patterns"></a>

各個 `\d` 命令都接受一個 *`pattern`* 參數，用來指定要顯示的物件名稱。在最簡單的情況下，模式就是物件的確切名稱。模式中的字元通常會轉為小寫，就像 SQL 名稱一樣；例如，`\dt FOO` 會顯示名為 `foo` 的資料表。與 SQL 名稱一樣，在模式兩側加上雙引號可以避免轉為小寫。若需要在模式中包含實際的雙引號字元，請在雙引號序列中將它寫成一對雙引號；這同樣符合 SQL 帶引號識別字的規則。例如，`\dt "FOO""BAR"` 會顯示名為 `FOO"BAR`（而不是 `foo"bar`）的資料表。與 SQL 名稱的一般規則不同，你可以只對模式的一部分加上雙引號，例如 `\dt FOO"FOO"BAR` 會顯示名為 `fooFOObar` 的資料表。

每當完全省略 *`pattern`* 參數時，`\d` 命令會顯示目前綱要搜尋路徑中所有可見的物件——這等同於使用 `*` 作為模式。（若一個物件所在的綱要位於搜尋路徑中，且搜尋路徑中較前面沒有出現同類同名的物件，就稱該物件為*可見*的。這等同於說，該物件不必明確加上綱要限定就能以名稱參照。）若要查看資料庫中所有物件而不論其可見性，請使用 `*.*` 作為模式。

在模式中，`*` 比對任意字元序列（包括零個字元），`?` 比對任意單一字元。（此表示法與 Unix shell 的檔名模式相當。）例如，`\dt int*` 會顯示名稱以 `int` 開頭的資料表。但在雙引號內，`*` 與 `?` 會失去這些特殊意義，只會按字面比對。

含有一個點（`.`）的關聯模式，會被解讀為綱要名稱模式後接物件名稱模式。例如，`\dt foo*.*bar*` 會顯示所有位於綱要名稱以 `foo` 開頭之綱要中、且資料表名稱包含 `bar` 的資料表。若沒有出現點，則模式只會比對在目前綱要搜尋路徑中可見的物件。同樣地，雙引號內的點會失去其特殊意義，只會按字面比對。含有兩個點（`.`）的關聯模式，會被解讀為資料庫名稱後接綱要名稱模式，再接物件名稱模式。資料庫名稱的部分不會被當成模式，而且必須與目前連線的資料庫名稱相符，否則會引發錯誤。

含有一個點（`.`）的綱要模式，會被解讀為資料庫名稱後接綱要名稱模式。例如，`\dn mydb.*foo*` 會顯示所有綱要名稱包含 `foo` 的綱要。資料庫名稱的部分不會被當成模式，而且必須與目前連線的資料庫名稱相符，否則會引發錯誤。

進階使用者可以使用正規表示式的表示法，例如字元類別，像是用 `[0-9]` 比對任何數字。所有正規表示式特殊字元的運作方式都如[第 9.7.3 節](https://docs.postgresql.tw/19/the-sql-language/functions/functions-matching/functions-posix-regexp.md#functions-posix-regexp)所述，但以下例外：`.` 會如上所述被當成分隔符號，`*` 會被轉換為正規表示式表示法 `.*`，`?` 會被轉換為 `.`，而 `$` 則按字面比對。必要時，你可以寫 `?` 來代替 `.`、寫 `(R+|)` 來代替 `R*`，或寫 `(R|)` 來代替 `R?`，以模擬這些模式字元。`$` 不需要作為正規表示式字元，因為模式必須比對整個名稱，這與正規表示式的一般解讀方式不同（換句話說，`$` 會自動附加到你的模式後面）。若不希望模式被錨定，請在開頭和（或）結尾寫上 `*`。請注意，在雙引號內，所有正規表示式特殊字元都會失去其特殊意義，只會按字面比對。此外，在運算子名稱模式（亦即 `\do` 的引數）中，正規表示式特殊字元會按字面比對。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/app-psql.html)（原文版本：18.6；核對日期：2026-10-17）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/reference/reference-client/app-psql/app-psql-patterns.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
