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

# 8.8. 幾何型別 \#

### 8.8. 幾何型別 [#](#datatype-geometric) <a href="#datatype-geometric" id="datatype-geometric"></a>

[8.8.1. 點](#datatype-geometric-points)

[8.8.2. 直線](#datatype-line)

[8.8.3. 線段](#datatype-lseg)

[8.8.4. 方框](#datatype-geometric-boxes)

[8.8.5. 路徑](#datatype-geometric-paths)

[8.8.6. 多邊形](#datatype-polygon)

[8.8.7. 圓形](#datatype-circle)

幾何資料型別用來表示二維空間 物件。[表 8.20](#datatype-geometric-table) 顯示了 PostgreSQL 中可用的幾何 型別。

#### 表 8.20. 幾何型別 [#](#datatype-geometric-table) <a href="#datatype-geometric-table" id="datatype-geometric-table"></a>

| 名稱        | 儲存大小       | 說明          | 表示法                |
| --------- | ---------- | ----------- | ------------------ |
| `point`   | 16 位元組     | 平面上的點       | (x,y)              |
| `line`    | 24 位元組     | 無限長直線       | {A,B,C}            |
| `lseg`    | 32 位元組     | 有限長線段       | \[(x1,y1),(x2,y2)] |
| `box`     | 32 位元組     | 矩形方框        | (x1,y1),(x2,y2)    |
| `path`    | 16+16n 位元組 | 封閉路徑（類似多邊形） | ((x1,y1),...)      |
| `path`    | 16+16n 位元組 | 開放路徑        | \[(x1,y1),...]     |
| `polygon` | 40+16n 位元組 | 多邊形（類似封閉路徑） | ((x1,y1),...)      |
| `circle`  | 24 位元組     | 圓形          | <(x,y),r>（圓心與半徑）   |

<br>

在以上所有型別中，個別座標都是以 `double precision`（`float8`）數字儲存。

有一整套豐富的函式與運算子，可用來執行各種幾何 運算，例如縮放、平移、旋轉，以及判斷相交情形。詳情請見[9.11 節](https://docs.postgresql.tw/19/the-sql-language/functions/functions-geometry.md)。

#### 8.8.1. 點 [#](#datatype-geometric-points) <a href="#datatype-geometric-points" id="datatype-geometric-points"></a>

點是幾何型別最基本的二維建構單元。`point` 型別的值，可使用下列任一語法指定：

```

( x , y )
  x , y
```

其中 *`x`* 與 *`y`* 分別是以浮點數表示的 座標值。

點在輸出時採用第一種語法。

#### 8.8.2. 直線 [#](#datatype-line) <a href="#datatype-line" id="datatype-line"></a>

直線是以線性方程式 \*`A`\*x + \*`B`\*y + *`C`* = 0 表示，其中 *`A`* 與 *`B`* 不能同時為零。`line` 型別的值，其輸入與輸出皆採用下列形式：

```

{ A, B, C }
```

或者，輸入時也可以使用下列任一形式：

```

[ ( x1 , y1 ) , ( x2 , y2 ) ]
( ( x1 , y1 ) , ( x2 , y2 ) )
  ( x1 , y1 ) , ( x2 , y2 )
    x1 , y1   ,   x2 , y2
```

其中 `(x1,y1)` 與 `(x2,y2)` 是該直線上的兩個相異點。

#### 8.8.3. 線段 [#](#datatype-lseg) <a href="#datatype-lseg" id="datatype-lseg"></a>

線段是以該線段兩端點的座標對來表示。`lseg` 型別的值，可使用下列任一 語法指定：

```

[ ( x1 , y1 ) , ( x2 , y2 ) ]
( ( x1 , y1 ) , ( x2 , y2 ) )
  ( x1 , y1 ) , ( x2 , y2 )
    x1 , y1   ,   x2 , y2
```

其中 `(x1,y1)` 與 `(x2,y2)` 是該線段的端點。

線段在輸出時採用第一種語法。

#### 8.8.4. 方框 [#](#datatype-geometric-boxes) <a href="#datatype-geometric-boxes" id="datatype-geometric-boxes"></a>

方框是以該方框兩個對角頂點的座標對來表示。 `box` 型別的值，可使用下列任一 語法指定：

```

( ( x1 , y1 ) , ( x2 , y2 ) )
  ( x1 , y1 ) , ( x2 , y2 )
    x1 , y1   ,   x2 , y2
```

其中 `(x1,y1)` 與 `(x2,y2)` 是該方框任意一組對角頂點。

方框在輸出時採用第二種語法。

輸入時可提供任意一組對角頂點，但系統會視需要 重新排列這些值，依序儲存為 右上角與左下角。

#### 8.8.5. 路徑 [#](#datatype-geometric-paths) <a href="#datatype-geometric-paths" id="datatype-geometric-paths"></a>

路徑是以一連串相連的點來表示。路徑可以是 *開放的*，此時清單中第一個與最後一個點視為不相連；也可以是 *封閉的*， 此時第一個與最後一個點視為相連。

`path` 型別的值，可使用下列任一 語法指定：

```

[ ( x1 , y1 ) , ... , ( xn , yn ) ]
( ( x1 , y1 ) , ... , ( xn , yn ) )
  ( x1 , y1 ) , ... , ( xn , yn )
  ( x1 , y1   , ... ,   xn , yn )
    x1 , y1   , ... ,   xn , yn
```

其中這些點是構成該路徑之線段的端點。方括號（`[]`）表示 開放路徑，而括號（`()`）則表示 封閉路徑。當省略最外層的括號時，如 第三到第五種語法所示，則預設為封閉路徑。

路徑在輸出時，視情況採用第一種或第二種語法。

#### 8.8.6. 多邊形 [#](#datatype-polygon) <a href="#datatype-polygon" id="datatype-polygon"></a>

多邊形是以一系列點（多邊形的頂點）來表示。多邊形與封閉路徑 非常相似；兩者本質上的語意差異在於，多邊形被視為包含其 內部的區域，而路徑則不是。

多邊形與路徑之間一項重要的實作差異在於，多邊形的儲存表示法 包含其最小外接方框。這可加快某些搜尋 運算的速度，不過在建構新的多邊形時，計算外接方框也會增加額外開銷。

`polygon` 型別的值，可使用下列任一 語法指定：

```

( ( x1 , y1 ) , ... , ( xn , yn ) )
  ( x1 , y1 ) , ... , ( xn , yn )
  ( x1 , y1   , ... ,   xn , yn )
    x1 , y1   , ... ,   xn , yn
```

其中這些點是構成該多邊形邊界之線段的端點。

多邊形在輸出時採用第一種語法。

#### 8.8.7. 圓形 [#](#datatype-circle) <a href="#datatype-circle" id="datatype-circle"></a>

圓形是以圓心與半徑來表示。 `circle` 型別的值，可使用下列任一 語法指定：

```

< ( x , y ) , r >
( ( x , y ) , r )
  ( x , y ) , r
    x , y   , r
```

其中 `(x,y)` 是圓心，*`r`* 則是該 圓形的半徑。

圓形在輸出時採用第一種語法。

***

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


---

# 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/datatype/datatype-geometric.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.
