> 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/internals/protocol/protocol-error-fields.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 54.8. 錯誤與通知訊息欄位 \#

### 54.8. 錯誤與通知訊息欄位 [#](#protocol-error-fields) <a href="#protocol-error-fields" id="protocol-error-fields"></a>

本節說明可以出現在 ErrorResponse 與 NoticeResponse 訊息中的欄位。每種欄位類型都有一個單一位元組的識別記號。請注意，任何一種欄位類型在每則訊息中都應該最多只出現一次。

`S` : 嚴重性：欄位內容為 `ERROR`、`FATAL` 或 `PANIC`（於錯誤訊息中），或為 `WARNING`、`NOTICE`、`DEBUG`、`INFO` 或 `LOG`（於通知訊息中），或為其中之一的在地化翻譯。一定會出現。

`V` : 嚴重性：欄位內容為 `ERROR`、`FATAL` 或 `PANIC`（於錯誤訊息中），或為 `WARNING`、`NOTICE`、`DEBUG`、`INFO` 或 `LOG`（於通知訊息中）。此欄位與 `S` 欄位相同，只是其內容永遠不會在地化。只有 PostgreSQL 9.6 及之後版本所產生的訊息中才會有此欄位。

`C` : 代碼：該錯誤的 SQLSTATE 代碼（請參閱[附錄 A](https://docs.postgresql.tw/19/appendixes/errcodes-appendix.md)）。不可在地化。一定會出現。

`M` : 訊息：主要的、供人閱讀的錯誤訊息。此訊息應該精確而簡潔（通常為一行）。一定會出現。

`D` : 詳細資訊：選擇性的次要錯誤訊息，帶有關於該問題的更多詳細資訊。可能跨越多行。

`H` : 提示：關於如何處理該問題的選擇性建議。它與「詳細資訊」的不同之處在於，它提供的是建議（可能不適用），而不是確切的事實。可能跨越多行。

`P` : 位置：欄位值為十進位 ASCII 整數，表示錯誤游標的位置，以原始查詢字串中的索引表示。第一個字元的索引為 1，位置以字元而非位元組計算。

`p` : 內部位置：其定義與 `P` 欄位相同，但用於游標位置指向內部產生的命令、而非用戶端所提交命令的情況。出現此欄位時，一定也會出現 `q` 欄位。

`q` : 內部查詢：失敗的內部產生命令的文字。例如，這可能是由 PL/pgSQL 函式所發出的 SQL 查詢。

`W` : 所在情境：指出錯誤發生時的情境。目前這包括作用中程序語言函式與內部產生查詢的呼叫堆疊追溯。追溯內容每行一個項目，最近的在最前面。

`s` : 綱要名稱：若錯誤與特定資料庫物件相關，則為包含該物件的綱要名稱（若有的話）。

`t` : 資料表名稱：若錯誤與特定資料表相關，則為該資料表的名稱。（該資料表所屬綱要的名稱，請參閱綱要名稱欄位。）

`c` : 欄位名稱：若錯誤與特定資料表欄位相關，則為該欄位的名稱。（請參閱綱要名稱與資料表名稱欄位以識別該資料表。）

`d` : 資料型別名稱：若錯誤與特定資料型別相關，則為該資料型別的名稱。（該資料型別所屬綱要的名稱，請參閱綱要名稱欄位。）

`n` : 限制條件名稱：若錯誤與特定限制條件相關，則為該限制條件的名稱。相關聯的資料表或網域，請參閱上面所列的欄位。（就此用途而言，索引會被視為限制條件，即使它們不是以限制條件語法建立的。）

`F` : 檔案：回報錯誤之原始碼位置的檔案名稱。

`L` : 行號：回報錯誤之原始碼位置的行號。

`R` : 常式：回報錯誤之原始碼常式的名稱。

#### 注意

綱要名稱、資料表名稱、欄位名稱、資料型別名稱與限制條件名稱這些欄位，只會針對有限的幾種錯誤類型提供；請參閱[附錄 A](https://docs.postgresql.tw/19/appendixes/errcodes-appendix.md)。前端不應該假設這些欄位中任何一個的存在，就保證另一個欄位也會存在。核心的錯誤來源會遵守上述的相互關係，但使用者自訂的函式可能會以其他方式使用這些欄位。同樣地，用戶端不應該假設這些欄位代表目前資料庫中當下存在的物件。

用戶端負責將顯示的資訊格式化以符合其需求；特別是，它應該視需要將過長的行換行。出現在錯誤訊息欄位中的換行字元應該被視為段落分隔，而不是換行。

***

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


---

# 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/internals/protocol/protocol-error-fields.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.
