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

# 第 4 章 SQL 語法

**目錄**

* [4.1. 詞彙結構](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-lexical.md)
  * [4.1.1. 識別字與關鍵字](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-lexical.md#sql-syntax-identifiers)
  * [4.1.2. 常數](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-lexical/sql-syntax-constants.md#sql-syntax-constants)
  * [4.1.3. 運算子](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-lexical.md#sql-syntax-operators)
  * [4.1.4. 特殊字元](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-lexical.md#sql-syntax-special-chars)
  * [4.1.5. 註解](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-lexical.md#sql-syntax-comments)
  * [4.1.6. 運算子優先順序](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-lexical/sql-precedence.md#sql-precedence)
* [4.2. 值運算式](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md)
  * [4.2.1. 欄位參照](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#sql-expressions-column-refs)
  * [4.2.2. 位置參數](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#sql-expressions-parameters-positional)
  * [4.2.3. 下標](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#sql-expressions-subscripts)
  * [4.2.4. 欄位選取](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#field-selection)
  * [4.2.5. 運算子呼叫](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#sql-expressions-operator-calls)
  * [4.2.6. 函式呼叫](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#sql-expressions-function-calls)
  * [4.2.7. 彙總運算式](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#syntax-aggregates)
  * [4.2.8. Window 函式呼叫](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#syntax-window-functions)
  * [4.2.9. 型別轉換](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#sql-syntax-type-casts)
  * [4.2.10. 定序運算式](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#sql-syntax-collate-exprs)
  * [4.2.11. 純量子查詢](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#sql-syntax-scalar-subqueries)
  * [4.2.12. 陣列建構子](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#sql-syntax-array-constructors)
  * [4.2.13. 資料列建構子](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#sql-syntax-row-constructors)
  * [4.2.14. 運算式求值規則](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-expressions.md#syntax-express-eval)
* [4.3. 呼叫函式](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-calling-funcs.md)
  * [4.3.1. 使用位置表示法](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-calling-funcs.md#sql-syntax-calling-funcs-positional)
  * [4.3.2. 使用具名表示法](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-calling-funcs.md#sql-syntax-calling-funcs-named)
  * [4.3.3. 使用混合表示法](https://docs.postgresql.tw/19/the-sql-language/sql-syntax/sql-syntax-calling-funcs.md#sql-syntax-calling-funcs-mixed)

本章說明 SQL 的語法。它是理解後續各章的基礎，後續各章會詳細說明如何運用 SQL 指令來定義與修改資料。

我們也建議已經熟悉 SQL 的使用者仔細閱讀本章，因為其中包含一些在各 SQL 資料庫之間實作並不一致，或是 PostgreSQL 特有的規則與概念。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/sql-syntax.html)（原文版本：18.6；核對日期：2026-09-11）


---

# 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/the-sql-language/sql-syntax.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.
