# F.46. tsm\_system\_rows

tsm\_system\_rows 模組提供資料表抽樣方法 SYSTEM\_ROWS，此方法可在 [SELECT](/15/reference/sql-commands/select.md) 指令的 TABLESAMPLE 子句中使用。

此資料表抽樣方法接受整數的參數，該參數是要讀取的最大資料筆數。除非資料表沒有足夠的資料，結果樣本將恰好包含那麼多筆資料；否則在這種情況下，將回傳整個資料表。

像內建的 SYSTEM 抽樣方法一樣，SYSTEM\_ROWS 執行區塊策略抽樣，因此抽樣並不是完全隨機的，但可能會有些群聚的效應，尤其是在僅要求少量資料的情況下。

SYSTEM\_ROWS 不支援 REPEATABLE 子句。

## F.46.1. 範例

使用 SYSTEM\_ROWS 選擇資料表樣本的範例。首先要安裝延伸功能：

```
CREATE EXTENSION tsm_system_rows;
```

然後，您可以在 SELECT 指令中使用它，例如：

```
SELECT * FROM my_table TABLESAMPLE SYSTEM_ROWS(100);
```

此命令將從資料表 my\_table 回傳 100 筆資料的樣本（除非該資料表沒有 100 筆資料，在這種情況下將回傳其所有資料）。


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.postgresql.tw/15/appendixes/additional-supplied-modules/tsm_system_rows.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
