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

# 5.2. 預設值 \#

### 5.2. 預設值 [#](#ddl-default) <a href="#ddl-default" id="ddl-default"></a>

欄位可以被指定一個預設值。當建立新的資料列，而某些欄位沒有指定值時，這些欄位就會填入各自的預設值。資料操作指令也可以明確地要求將某個欄位設為它的預設值，而不需要知道那個值究竟是什麼。（資料操作指令的細節請參閱[第 6 章](https://docs.postgresql.tw/19/the-sql-language/dml.md)。）

如果沒有明確宣告預設值，預設值就是空值。這通常是合理的，因為空值可以視為代表未知的資料。

在資料表定義中，預設值列在欄位資料型別之後。例如：

```

CREATE TABLE products (
    product_no integer,
    name text,
    price numeric DEFAULT 9.99
);
```

預設值可以是一個運算式，它會在每次插入預設值時被求值（*而不是*在資料表建立時）。常見的例子是讓 `timestamp` 欄位的預設值為 `CURRENT_TIMESTAMP`，這樣它就會被設成資料列插入時的時間。另一個常見的例子是為每一筆資料列產生「序號」。在 PostgreSQL 中，這通常是以類似下面的方式來完成：

```

CREATE TABLE products (
    product_no integer DEFAULT nextval('products_product_no_seq'),
    ...
);
```

其中 `nextval()` 函式會從*序列物件*提供接續的值（請參閱[第 9.17 節](https://docs.postgresql.tw/19/the-sql-language/functions/functions-sequence.md)）。這種安排相當常見，因此有一個特別的簡寫方式：

```

CREATE TABLE products (
    product_no SERIAL,
    ...
);
```

`SERIAL` 簡寫在[第 8.1.4 節](https://docs.postgresql.tw/19/the-sql-language/datatype/datatype-numeric.md#datatype-serial)中有進一步的說明。

***

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


---

# 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/ddl/ddl-default.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.
