This is an automated email from the ASF dual-hosted git repository.
zclll pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push:
new d24391e953c [Feature](function) Support function DEFAULT (#3029)
d24391e953c is described below
commit d24391e953c8c0729f41e8696c810b3d01f25088
Author: linrrarity <[email protected]>
AuthorDate: Sat Jan 24 03:12:27 2026 +0800
[Feature](function) Support function DEFAULT (#3029)
## Versions
- [x] dev
- [x] 4.x
- [ ] 3.x
- [ ] 2.1
## Languages
- [x] Chinese
- [x] English
## Docs Checklist
- [ ] Checked by AI
- [ ] Test Cases Built
---
.../scalar-functions/other-functions/default.md | 183 ++++++++++++++++++++
.../scalar-functions/other-functions/default.md | 183 ++++++++++++++++++++
.../scalar-functions/other-functions/default.md | 187 +++++++++++++++++++++
sidebars.ts | 1 +
.../scalar-functions/other-functions/default.md | 187 +++++++++++++++++++++
versioned_sidebars/version-4.x-sidebars.json | 1 +
6 files changed, 742 insertions(+)
diff --git
a/docs/sql-manual/sql-functions/scalar-functions/other-functions/default.md
b/docs/sql-manual/sql-functions/scalar-functions/other-functions/default.md
new file mode 100644
index 00000000000..1d7bd000cf5
--- /dev/null
+++ b/docs/sql-manual/sql-functions/scalar-functions/other-functions/default.md
@@ -0,0 +1,183 @@
+---
+{
+ "title": "DEFAULT",
+ "language": "en"
+}
+---
+
+## Description
+
+Returns the default value of a specific column in a table. If the column has
no default value, an error is thrown.
+
+This function behaves the same as MySQL's DEFAULT function.
+
+## Syntax
+
+```sql
+DEFAULT(<column>)
+```
+
+## Parameters
+
+| Parameter | Description |
+| --- | --- |
+| `<column>` | The column whose default value is queried. Only columns are
accepted; otherwise an error is thrown. |
+
+## Return Value
+
+Returns the column’s default value, with the same type as the column
+- If a default is set, returns that default value
+- If no default is set and the column is not NOT NULL, returns NULL
+- If no default is set and the column is NOT NULL, an error is thrown
+
+Special cases:
+- Only columns are allowed as input; if a constant (including NULL) or an
expression is provided, an error is thrown
+- When the input is an auto-increment column or a generated column, an error
is thrown
+
+[Doris-supported default value related
parameters](../../../sql-statements/table-and-view/table/CREATE-TABLE.md#Column-Default-Value-Related-Parameters)
+
+## Examples
+
+1. Non-aggregate types with constant default values
+```sql
+-- setup
+-- Columns without an explicitly defined DEFAULT accept only NULL as the
default value
+-- ARRAY type default values only accept `[]` and NULL
+CREATE TABLE test_default_scalar (
+ c_bool BOOLEAN NULL
DEFAULT 1,
+ c_tinyint TINYINT NULL
DEFAULT 7,
+ c_smallint SMALLINT NULL
DEFAULT 32000,
+ c_int INT NULL
DEFAULT 2147483647,
+ c_bigint BIGINT NULL
DEFAULT 9223372036854775807,
+ c_largeint LARGEINT NULL
DEFAULT '170141183460469231731687303715884105727',
+ c_float FLOAT NULL
DEFAULT 3.125,
+ c_double DOUBLE NULL
DEFAULT 2.718281828,
+ c_decimal DECIMAL(27, 9) NULL
DEFAULT '123456789.123456789',
+ c_decimal_compact DECIMAL(18, 4) NULL
DEFAULT '99999.1234',
+ c_pi DOUBLE NULL
DEFAULT PI,
+ c_e DOUBLE NULL
DEFAULT E,
+ c_char CHAR(8) NULL
DEFAULT 'charDemo',
+ c_varchar VARCHAR(32) NULL
DEFAULT '',
+ c_string STRING NULL
DEFAULT 'plain string',
+ c_datetime DATETIME NULL
DEFAULT '2025-10-25 11:22:33',
+ c_date DATE NULL
DEFAULT '2025-10-31',
+ c_json JSON NULL,
+ c_ipv4 IPV4 NULL
DEFAULT '192.168.1.1',
+ c_ipv6 IPV6 NULL
DEFAULT '2001:db8::1',
+ c_array_int ARRAY<INT> NULL
DEFAULT '[]',
+ c_array_string ARRAY<STRING> NULL,
+ c_map_str_int MAP<STRING, INT> NULL,
+ c_struct STRUCT<f1:INT,f2:STRING,f3:BOOLEAN> NULL,
+ c_variant VARIANT NULL
+) PROPERTIES ( 'replication_num' = '1');
+
+-- INSERT statements omitted in the example
+SELECT
+ DEFAULT(c_bool),
+ DEFAULT(c_tinyint),
+ DEFAULT(c_smallint),
+ DEFAULT(c_int),
+ DEFAULT(c_bigint),
+ DEFAULT(c_largeint),
+ DEFAULT(c_float),
+ DEFAULT(c_double),
+ DEFAULT(c_decimal),
+ DEFAULT(c_decimal_compact),
+ DEFAULT(c_pi),
+ DEFAULT(c_e),
+ DEFAULT(c_char),
+ DEFAULT(c_varchar),
+ DEFAULT(c_string),
+ DEFAULT(c_datetime),
+ DEFAULT(c_date),
+ DEFAULT(c_json),
+ DEFAULT(c_ipv4),
+ DEFAULT(c_ipv6),
+ DEFAULT(c_array_int),
+ DEFAULT(c_array_string),
+ DEFAULT(c_map_str_int),
+ DEFAULT(c_struct),
+ DEFAULT(c_variant)
+FROM test_default_scalar
+LIMIT 1;
+```
+```text
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+| DEFAULT(c_bool) | DEFAULT(c_tinyint) | DEFAULT(c_smallint) | DEFAULT(c_int)
| DEFAULT(c_bigint) | DEFAULT(c_largeint) |
DEFAULT(c_float) | DEFAULT(c_double) | DEFAULT(c_decimal) |
DEFAULT(c_decimal_compact) | DEFAULT(c_pi) | DEFAULT(c_e) |
DEFAULT(c_char) | DEFAULT(c_varchar) | DEFAULT(c_string) | DEFAULT(c_datetime)
| DEFAULT(c_date) | DEFAULT(c_json) | DEFAULT(c_ipv4) | DEFAULT(c_ipv6) |
DEFAULT(c_array_int) | DEFAULT(c_array_string) | DEFAULT(c_map_st [...]
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+| 1 | 7 | 32000 | 2147483647
| 9223372036854775807 | 170141183460469231731687303715884105727 |
3.125 | 2.718281828 | 123456789.123456789 | 99999.1234 |
3.141592653589793 | 2.718281828459045 | charDemo | |
plain string | 2025-10-25 11:22:33 | 2025-10-31 | NULL |
192.168.1.1 | 2001:db8::1 | [] | NULL
| NULL [...]
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+```
+
+2. Aggregate types example
+```sql
+CREATE TABLE test_default_agg (
+ k_id INT NOT NULL COMMENT 'aggregation key',
+ bitmap_col BITMAP BITMAP_UNION,
+ hll_col HLL HLL_UNION,
+ quantile_col QUANTILE_STATE QUANTILE_UNION
+) AGGREGATE KEY(k_id)
+PROPERTIES ( 'replication_num' = '1' );
+
+SELECT
+ default(bitmap_col),default(hll_col)
+FROM test_default_agg
+LIMIT 1;
+```
+```text
++---------------------+------------------+
+| default(bitmap_col) | default(hll_col) |
++---------------------+------------------+
+| NULL | NULL |
++---------------------+------------------+
+```
+
+3. Non-constant defaults (`CURRENT_TIMESTAMP`, `CURRENT_DATE`) example:
+```sql
+CREATE TABLE test_default_time(
+ tm DATETIME(5) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
+ dt DATE DEFAULT CURRENT_DATE
+) PROPERTIES( 'replication_num' = '1' );
+
+SELECT DEFAULT(tm), DEFAULT(dt) FROM test_default_time;
+```
+```text
++---------------------------+-------------+
+| DEFAULT(tm) | DEFAULT(dt) |
++---------------------------+-------------+
+| 2026-01-23 17:32:10.90500 | 2026-01-23 |
++---------------------------+-------------+
+```
+
+4. Constant values
+```sql
+SELECT DEFAULT('hello');
+-- ERROR 1105 (HY000): errCode = 2, detailMessage =
+-- mismatched input ''hello'' expecting {'{', '}', 'ACTIONS', 'AFTER',
'AGG_STATE', 'AGGREGATE', 'ALIAS', 'ANALYZED', 'ARRAY', 'AT', 'AUTHORS',
'AUTO_INCREMENT', 'ALWAYS', 'BACKENDS', 'BACKUP', 'BEGIN', 'BELONG', 'BIN',
'BITAND', 'BITMAP', 'BITMAP_EMPTY', 'BITMAP_UNION', 'BITOR', 'BITXOR', 'BLOB',
'BOOLEAN', 'BRANCH', 'BRIEF', 'BROKER', 'BUCKETS', 'BUILD', 'BUILTIN', 'CACHE',
'CACHED', 'CALL', 'CATALOG', 'CATALOGS', 'CHAIN', CHAR, 'CHARSET', 'CHECK',
'CLUSTER', 'CLUSTERS', 'COLLA
+
+SELECT DEFAULT(NULL);
+-- ERROR 1105 (HY000): errCode = 2, detailMessage =
+-- mismatched input 'NULL' expecting {'{', '}', 'ACTIONS', 'AFTER',
'AGG_STATE', 'AGGREGATE', 'ALIAS', 'ANALYZED', 'ARRAY', 'AT', 'AUTHORS',
'AUTO_INCREMENT', 'ALWAYS', 'BACKENDS', 'BACKUP', 'BEGIN', 'BELONG', 'BIN',
'BITAND', 'BITMAP', 'BITMAP_EMPTY', 'BITMAP_UNION', 'BITOR', 'BITXOR', 'BLOB',
'BOOLEAN', 'BRANCH', 'BRIEF', 'BROKER', 'BUCKETS', 'BUILD', 'BUILTIN', 'CACHE',
'CACHED', 'CALL', 'CATALOG', 'CATALOGS', 'CHAIN', CHAR, 'CHARSET', 'CHECK',
'CLUSTER', 'CLUSTERS', 'COLLATIO
+```
+
+5. Auto-increment column
+```sql
+CREATE TABLE test_auto_inc (
+ id BIGINT NULL AUTO_INCREMENT,
+ value BIGINT NOT NULL
+) PROPERTIES ('replication_num' = '1' );
+
+INSERT INTO test_auto_inc(value) VALUES (1), (2);
+--ERROR 1105 (HY000): errCode = 2, detailMessage = Column 'id' has no default
value and does not allow NULL or column is auto-increment
+```
+
+6. Generated column
+```sql
+CREATE TABLE test_gen_col (
+ a INT,
+ b INT AS (a + 10)
+) PROPERTIES ('replication_num' = '1' );
+
+SELECT DEFAULT(b) FROM test_gen_col;
+-- ERROR 1105 (HY000): errCode = 2, detailMessage = DEFAULT cannot be used on
generated column 'b'
+```
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/other-functions/default.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/other-functions/default.md
new file mode 100644
index 00000000000..b75b16ddb41
--- /dev/null
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/other-functions/default.md
@@ -0,0 +1,183 @@
+---
+{
+ "title": "DEFAULT",
+ "language": "zh-CN"
+}
+---
+
+## 描述
+
+返回表中特定列的默认值。如果该列没有默认值,则会抛出错误。
+
+该函数与 MySQL 中的 [DEFAULT
函数](https://dev.mysql.com/doc/refman/8.4/en/miscellaneous-functions.html#function_default)
行为一致
+
+## 语法
+
+```sql
+DEFAULT(<column>)
+```
+
+## 参数
+
+| 参数 | 说明 |
+| ---------- | ---------------------------------------------- |
+| `<column>` | 需要查询默认值的列。仅接受列,否则会抛出错误。 |
+
+## 返回值
+
+返回列的默认值,类型与列类型相同
+- 若有设置默认值,则返回对应的默认值
+- 若没有设置默认值,且列不为 NOT NULL, 则返回 NULL
+- 若没有设置默认值,且列为 NOT NULL, 则抛出错误
+
+特殊情况:
+- 输入参数仅允许列,当输入为常量(包括 NULL)或表达式时,抛出错误
+- 输入为自增列或生成列时,抛出错误
+
+[Doris
支持的默认值相关参数](../../../sql-statements/table-and-view/table/CREATE-TABLE.md#列的默认值相关参数)
+
+## 举例
+
+1. 非聚合类型常量默认值举例
+```sql
+-- setup
+-- 表中没有显示表明DEFAULT值的代表其默认值仅接受 NULL 值
+-- ARRAY 类型的默认值仅接受 `[]` 和 NULL
+CREATE TABLE test_default_scalar (
+ c_bool BOOLEAN NULL
DEFAULT 1,
+ c_tinyint TINYINT NULL
DEFAULT 7,
+ c_smallint SMALLINT NULL
DEFAULT 32000,
+ c_int INT NULL
DEFAULT 2147483647,
+ c_bigint BIGINT NULL
DEFAULT 9223372036854775807,
+ c_largeint LARGEINT NULL
DEFAULT '170141183460469231731687303715884105727',
+ c_float FLOAT NULL
DEFAULT 3.125,
+ c_double DOUBLE NULL
DEFAULT 2.718281828,
+ c_decimal DECIMAL(27, 9) NULL
DEFAULT '123456789.123456789',
+ c_decimal_compact DECIMAL(18, 4) NULL
DEFAULT '99999.1234',
+ c_pi DOUBLE NULL
DEFAULT PI,
+ c_e DOUBLE NULL
DEFAULT E,
+ c_char CHAR(8) NULL
DEFAULT 'charDemo',
+ c_varchar VARCHAR(32) NULL
DEFAULT '',
+ c_string STRING NULL
DEFAULT 'plain string',
+ c_datetime DATETIME NULL
DEFAULT '2025-10-25 11:22:33',
+ c_date DATE NULL
DEFAULT '2025-10-31',
+ c_json JSON NULL,
+ c_ipv4 IPV4 NULL
DEFAULT '192.168.1.1',
+ c_ipv6 IPV6 NULL
DEFAULT '2001:db8::1',
+ c_array_int ARRAY<INT> NULL
DEFAULT '[]',
+ c_array_string ARRAY<STRING> NULL,
+ c_map_str_int MAP<STRING, INT> NULL,
+ c_struct STRUCT<f1:INT,f2:STRING,f3:BOOLEAN> NULL,
+ c_variant VARIANT NULL
+) PROPERTIES ( 'replication_num' = '1');
+
+-- 例中省略 INSERT 语句
+SELECT
+ DEFAULT(c_bool),
+ DEFAULT(c_tinyint),
+ DEFAULT(c_smallint),
+ DEFAULT(c_int),
+ DEFAULT(c_bigint),
+ DEFAULT(c_largeint),
+ DEFAULT(c_float),
+ DEFAULT(c_double),
+ DEFAULT(c_decimal),
+ DEFAULT(c_decimal_compact),
+ DEFAULT(c_pi),
+ DEFAULT(c_e),
+ DEFAULT(c_char),
+ DEFAULT(c_varchar),
+ DEFAULT(c_string),
+ DEFAULT(c_datetime),
+ DEFAULT(c_date),
+ DEFAULT(c_json),
+ DEFAULT(c_ipv4),
+ DEFAULT(c_ipv6),
+ DEFAULT(c_array_int),
+ DEFAULT(c_array_string),
+ DEFAULT(c_map_str_int),
+ DEFAULT(c_struct),
+ DEFAULT(c_variant)
+FROM test_default_scalar
+LIMIT 1;
+```
+```text
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+| DEFAULT(c_bool) | DEFAULT(c_tinyint) | DEFAULT(c_smallint) | DEFAULT(c_int)
| DEFAULT(c_bigint) | DEFAULT(c_largeint) |
DEFAULT(c_float) | DEFAULT(c_double) | DEFAULT(c_decimal) |
DEFAULT(c_decimal_compact) | DEFAULT(c_pi) | DEFAULT(c_e) |
DEFAULT(c_char) | DEFAULT(c_varchar) | DEFAULT(c_string) | DEFAULT(c_datetime)
| DEFAULT(c_date) | DEFAULT(c_json) | DEFAULT(c_ipv4) | DEFAULT(c_ipv6) |
DEFAULT(c_array_int) | DEFAULT(c_array_string) | DEFAULT(c_map_st [...]
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+| 1 | 7 | 32000 | 2147483647
| 9223372036854775807 | 170141183460469231731687303715884105727 |
3.125 | 2.718281828 | 123456789.123456789 | 99999.1234 |
3.141592653589793 | 2.718281828459045 | charDemo | |
plain string | 2025-10-25 11:22:33 | 2025-10-31 | NULL |
192.168.1.1 | 2001:db8::1 | [] | NULL
| NULL [...]
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+```
+
+2. 聚合类型举例
+```sql
+CREATE TABLE test_default_agg (
+ k_id INT NOT NULL COMMENT '聚合键',
+ bitmap_col BITMAP BITMAP_UNION,
+ hll_col HLL HLL_UNION,
+ quantile_col QUANTILE_STATE QUANTILE_UNION
+) AGGREGATE KEY(k_id)
+PROPERTIES ( 'replication_num' = '1' );
+
+SELECT
+ default(bitmap_col),default(hll_col)
+FROM test_default_agg
+LIMIT 1;
+```
+```text
++---------------------+------------------+
+| default(bitmap_col) | default(hll_col) |
++---------------------+------------------+
+| NULL | NULL |
++---------------------+------------------+
+```
+
+3. 非常量默认值(`CURRENT_TIMESTAMP`, `CURRENT_DATE`)举例:
+```sql
+CREATE TABLE test_default_time(
+ tm DATETIME(5) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
+ dt DATE DEFAULT CURRENT_DATE
+) PROPERTIES( 'replication_num' = '1' );
+
+SELECT DEFAULT(tm), DEFAULT(dt) FROM test_default_time;
+```
+```text
++---------------------------+-------------+
+| DEFAULT(tm) | DEFAULT(dt) |
++---------------------------+-------------+
+| 2026-01-23 17:32:10.90500 | 2026-01-23 |
++---------------------------+-------------+
+```
+
+4. 常量值
+```sql
+SELECT DEFAULT('hello');
+-- ERROR 1105 (HY000): errCode = 2, detailMessage =
+-- mismatched input ''hello'' expecting {'{', '}', 'ACTIONS', 'AFTER',
'AGG_STATE', 'AGGREGATE', 'ALIAS', 'ANALYZED', 'ARRAY', 'AT', 'AUTHORS',
'AUTO_INCREMENT', 'ALWAYS', 'BACKENDS', 'BACKUP', 'BEGIN', 'BELONG', 'BIN',
'BITAND', 'BITMAP', 'BITMAP_EMPTY', 'BITMAP_UNION', 'BITOR', 'BITXOR', 'BLOB',
'BOOLEAN', 'BRANCH', 'BRIEF', 'BROKER', 'BUCKETS', 'BUILD', 'BUILTIN', 'CACHE',
'CACHED', 'CALL', 'CATALOG', 'CATALOGS', 'CHAIN', CHAR, 'CHARSET', 'CHECK',
'CLUSTER', 'CLUSTERS', 'COLLA
+
+SELECT DEFAULT(NULL);
+-- ERROR 1105 (HY000): errCode = 2, detailMessage =
+-- mismatched input 'NULL' expecting {'{', '}', 'ACTIONS', 'AFTER',
'AGG_STATE', 'AGGREGATE', 'ALIAS', 'ANALYZED', 'ARRAY', 'AT', 'AUTHORS',
'AUTO_INCREMENT', 'ALWAYS', 'BACKENDS', 'BACKUP', 'BEGIN', 'BELONG', 'BIN',
'BITAND', 'BITMAP', 'BITMAP_EMPTY', 'BITMAP_UNION', 'BITOR', 'BITXOR', 'BLOB',
'BOOLEAN', 'BRANCH', 'BRIEF', 'BROKER', 'BUCKETS', 'BUILD', 'BUILTIN', 'CACHE',
'CACHED', 'CALL', 'CATALOG', 'CATALOGS', 'CHAIN', CHAR, 'CHARSET', 'CHECK',
'CLUSTER', 'CLUSTERS', 'COLLATIO
+```
+
+5. 自增列
+```sql
+CREATE TABLE test_auto_inc (
+ id BIGINT NULL AUTO_INCREMENT,
+ value BIGINT NOT NULL
+) PROPERTIES ('replication_num' = '1' );
+
+INSERT INTO test_auto_inc(value) VALUES (1), (2);
+--ERROR 1105 (HY000): errCode = 2, detailMessage = Column 'id' has no default
value and does not allow NULL or column is auto-increment
+```
+
+6. 生成列
+```sql
+CREATE TABLE test_gen_col (
+ a INT,
+ b INT AS (a + 10)
+) PROPERTIES ('replication_num' = '1' );
+
+SELECT DEFAULT(b) FROM test_gen_col;
+-- ERROR 1105 (HY000): errCode = 2, detailMessage = DEFAULT cannot be used on
generated column 'b'
+```
\ No newline at end of file
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/other-functions/default.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/other-functions/default.md
new file mode 100644
index 00000000000..3b8ee38549c
--- /dev/null
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/other-functions/default.md
@@ -0,0 +1,187 @@
+---
+{
+ "title": "DEFAULT",
+ "language": "zh-CN"
+}
+---
+
+## 描述
+
+返回表中特定列的默认值。如果该列没有默认值,则会抛出错误。
+
+该函数与 MySQL 中的 [DEFAULT
函数](https://dev.mysql.com/doc/refman/8.4/en/miscellaneous-functions.html#function_default)
行为一致
+
+:::note
+该函数从4.0.4起开始支持
+:::
+
+## 语法
+
+```sql
+DEFAULT(<column>)
+```
+
+## 参数
+
+| 参数 | 说明 |
+| ---------- | ---------------------------------------------- |
+| `<column>` | 需要查询默认值的列。仅接受列,否则会抛出错误。 |
+
+## 返回值
+
+返回列的默认值,类型与列类型相同
+- 若有设置默认值,则返回对应的默认值
+- 若没有设置默认值,且列不为 NOT NULL, 则返回 NULL
+- 若没有设置默认值,且列为 NOT NULL, 则抛出错误
+
+特殊情况:
+- 输入参数仅允许列,当输入为常量(包括 NULL)或表达式时,抛出错误
+- 输入为自增列或生成列时,抛出错误
+
+[Doris
支持的默认值相关参数](../../../sql-statements/table-and-view/table/CREATE-TABLE.md#列的默认值相关参数)
+
+## 举例
+
+1. 非聚合类型常量默认值举例
+```sql
+-- setup
+-- 表中没有显示表明DEFAULT值的代表其默认值仅接受 NULL 值
+-- ARRAY 类型的默认值仅接受 `[]` 和 NULL
+CREATE TABLE test_default_scalar (
+ c_bool BOOLEAN NULL
DEFAULT 1,
+ c_tinyint TINYINT NULL
DEFAULT 7,
+ c_smallint SMALLINT NULL
DEFAULT 32000,
+ c_int INT NULL
DEFAULT 2147483647,
+ c_bigint BIGINT NULL
DEFAULT 9223372036854775807,
+ c_largeint LARGEINT NULL
DEFAULT '170141183460469231731687303715884105727',
+ c_float FLOAT NULL
DEFAULT 3.125,
+ c_double DOUBLE NULL
DEFAULT 2.718281828,
+ c_decimal DECIMAL(27, 9) NULL
DEFAULT '123456789.123456789',
+ c_decimal_compact DECIMAL(18, 4) NULL
DEFAULT '99999.1234',
+ c_pi DOUBLE NULL
DEFAULT PI,
+ c_e DOUBLE NULL
DEFAULT E,
+ c_char CHAR(8) NULL
DEFAULT 'charDemo',
+ c_varchar VARCHAR(32) NULL
DEFAULT '',
+ c_string STRING NULL
DEFAULT 'plain string',
+ c_datetime DATETIME NULL
DEFAULT '2025-10-25 11:22:33',
+ c_date DATE NULL
DEFAULT '2025-10-31',
+ c_json JSON NULL,
+ c_ipv4 IPV4 NULL
DEFAULT '192.168.1.1',
+ c_ipv6 IPV6 NULL
DEFAULT '2001:db8::1',
+ c_array_int ARRAY<INT> NULL
DEFAULT '[]',
+ c_array_string ARRAY<STRING> NULL,
+ c_map_str_int MAP<STRING, INT> NULL,
+ c_struct STRUCT<f1:INT,f2:STRING,f3:BOOLEAN> NULL,
+ c_variant VARIANT NULL
+) PROPERTIES ( 'replication_num' = '1');
+
+-- 例中省略 INSERT 语句
+SELECT
+ DEFAULT(c_bool),
+ DEFAULT(c_tinyint),
+ DEFAULT(c_smallint),
+ DEFAULT(c_int),
+ DEFAULT(c_bigint),
+ DEFAULT(c_largeint),
+ DEFAULT(c_float),
+ DEFAULT(c_double),
+ DEFAULT(c_decimal),
+ DEFAULT(c_decimal_compact),
+ DEFAULT(c_pi),
+ DEFAULT(c_e),
+ DEFAULT(c_char),
+ DEFAULT(c_varchar),
+ DEFAULT(c_string),
+ DEFAULT(c_datetime),
+ DEFAULT(c_date),
+ DEFAULT(c_json),
+ DEFAULT(c_ipv4),
+ DEFAULT(c_ipv6),
+ DEFAULT(c_array_int),
+ DEFAULT(c_array_string),
+ DEFAULT(c_map_str_int),
+ DEFAULT(c_struct),
+ DEFAULT(c_variant)
+FROM test_default_scalar
+LIMIT 1;
+```
+```text
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+| DEFAULT(c_bool) | DEFAULT(c_tinyint) | DEFAULT(c_smallint) | DEFAULT(c_int)
| DEFAULT(c_bigint) | DEFAULT(c_largeint) |
DEFAULT(c_float) | DEFAULT(c_double) | DEFAULT(c_decimal) |
DEFAULT(c_decimal_compact) | DEFAULT(c_pi) | DEFAULT(c_e) |
DEFAULT(c_char) | DEFAULT(c_varchar) | DEFAULT(c_string) | DEFAULT(c_datetime)
| DEFAULT(c_date) | DEFAULT(c_json) | DEFAULT(c_ipv4) | DEFAULT(c_ipv6) |
DEFAULT(c_array_int) | DEFAULT(c_array_string) | DEFAULT(c_map_st [...]
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+| 1 | 7 | 32000 | 2147483647
| 9223372036854775807 | 170141183460469231731687303715884105727 |
3.125 | 2.718281828 | 123456789.123456789 | 99999.1234 |
3.141592653589793 | 2.718281828459045 | charDemo | |
plain string | 2025-10-25 11:22:33 | 2025-10-31 | NULL |
192.168.1.1 | 2001:db8::1 | [] | NULL
| NULL [...]
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+```
+
+2. 聚合类型举例
+```sql
+CREATE TABLE test_default_agg (
+ k_id INT NOT NULL COMMENT '聚合键',
+ bitmap_col BITMAP BITMAP_UNION,
+ hll_col HLL HLL_UNION,
+ quantile_col QUANTILE_STATE QUANTILE_UNION
+) AGGREGATE KEY(k_id)
+PROPERTIES ( 'replication_num' = '1' );
+
+SELECT
+ default(bitmap_col),default(hll_col)
+FROM test_default_agg
+LIMIT 1;
+```
+```text
++---------------------+------------------+
+| default(bitmap_col) | default(hll_col) |
++---------------------+------------------+
+| NULL | NULL |
++---------------------+------------------+
+```
+
+3. 非常量默认值(`CURRENT_TIMESTAMP`, `CURRENT_DATE`)举例:
+```sql
+CREATE TABLE test_default_time(
+ tm DATETIME(5) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
+ dt DATE DEFAULT CURRENT_DATE
+) PROPERTIES( 'replication_num' = '1' );
+
+SELECT DEFAULT(tm), DEFAULT(dt) FROM test_default_time;
+```
+```text
++---------------------------+-------------+
+| DEFAULT(tm) | DEFAULT(dt) |
++---------------------------+-------------+
+| 2026-01-23 17:32:10.90500 | 2026-01-23 |
++---------------------------+-------------+
+```
+
+4. 常量值
+```sql
+SELECT DEFAULT('hello');
+-- ERROR 1105 (HY000): errCode = 2, detailMessage =
+-- mismatched input ''hello'' expecting {'{', '}', 'ACTIONS', 'AFTER',
'AGG_STATE', 'AGGREGATE', 'ALIAS', 'ANALYZED', 'ARRAY', 'AT', 'AUTHORS',
'AUTO_INCREMENT', 'ALWAYS', 'BACKENDS', 'BACKUP', 'BEGIN', 'BELONG', 'BIN',
'BITAND', 'BITMAP', 'BITMAP_EMPTY', 'BITMAP_UNION', 'BITOR', 'BITXOR', 'BLOB',
'BOOLEAN', 'BRANCH', 'BRIEF', 'BROKER', 'BUCKETS', 'BUILD', 'BUILTIN', 'CACHE',
'CACHED', 'CALL', 'CATALOG', 'CATALOGS', 'CHAIN', CHAR, 'CHARSET', 'CHECK',
'CLUSTER', 'CLUSTERS', 'COLLA
+
+SELECT DEFAULT(NULL);
+-- ERROR 1105 (HY000): errCode = 2, detailMessage =
+-- mismatched input 'NULL' expecting {'{', '}', 'ACTIONS', 'AFTER',
'AGG_STATE', 'AGGREGATE', 'ALIAS', 'ANALYZED', 'ARRAY', 'AT', 'AUTHORS',
'AUTO_INCREMENT', 'ALWAYS', 'BACKENDS', 'BACKUP', 'BEGIN', 'BELONG', 'BIN',
'BITAND', 'BITMAP', 'BITMAP_EMPTY', 'BITMAP_UNION', 'BITOR', 'BITXOR', 'BLOB',
'BOOLEAN', 'BRANCH', 'BRIEF', 'BROKER', 'BUCKETS', 'BUILD', 'BUILTIN', 'CACHE',
'CACHED', 'CALL', 'CATALOG', 'CATALOGS', 'CHAIN', CHAR, 'CHARSET', 'CHECK',
'CLUSTER', 'CLUSTERS', 'COLLATIO
+```
+
+5. 自增列
+```sql
+CREATE TABLE test_auto_inc (
+ id BIGINT NULL AUTO_INCREMENT,
+ value BIGINT NOT NULL
+) PROPERTIES ('replication_num' = '1' );
+
+INSERT INTO test_auto_inc(value) VALUES (1), (2);
+--ERROR 1105 (HY000): errCode = 2, detailMessage = Column 'id' has no default
value and does not allow NULL or column is auto-increment
+```
+
+6. 生成列
+```sql
+CREATE TABLE test_gen_col (
+ a INT,
+ b INT AS (a + 10)
+) PROPERTIES ('replication_num' = '1' );
+
+SELECT DEFAULT(b) FROM test_gen_col;
+-- ERROR 1105 (HY000): errCode = 2, detailMessage = DEFAULT cannot be used on
generated column 'b'
+```
\ No newline at end of file
diff --git a/sidebars.ts b/sidebars.ts
index d8ec0c98d14..be380eed883 100644
--- a/sidebars.ts
+++ b/sidebars.ts
@@ -1791,6 +1791,7 @@ const sidebars: SidebarsConfig = {
items: [
'sql-manual/sql-functions/scalar-functions/other-functions/convert-to',
'sql-manual/sql-functions/scalar-functions/other-functions/esquery',
+
'sql-manual/sql-functions/scalar-functions/other-functions/default',
'sql-manual/sql-functions/scalar-functions/other-functions/field',
'sql-manual/sql-functions/scalar-functions/other-functions/g',
'sql-manual/sql-functions/scalar-functions/other-functions/grouping',
diff --git
a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/other-functions/default.md
b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/other-functions/default.md
new file mode 100644
index 00000000000..23d53018300
--- /dev/null
+++
b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/other-functions/default.md
@@ -0,0 +1,187 @@
+---
+{
+ "title": "DEFAULT",
+ "language": "en"
+}
+---
+
+## Description
+
+Returns the default value of a specific column in a table. If the column has
no default value, an error is thrown.
+
+This function behaves the same as MySQL's DEFAULT function.
+
+:::note
+The function started supporting from 4.0.4.
+:::
+
+## Syntax
+
+```sql
+DEFAULT(<column>)
+```
+
+## Parameters
+
+| Parameter | Description |
+| --- | --- |
+| `<column>` | The column whose default value is queried. Only columns are
accepted; otherwise an error is thrown. |
+
+## Return Value
+
+Returns the column’s default value, with the same type as the column
+- If a default is set, returns that default value
+- If no default is set and the column is not NOT NULL, returns NULL
+- If no default is set and the column is NOT NULL, an error is thrown
+
+Special cases:
+- Only columns are allowed as input; if a constant (including NULL) or an
expression is provided, an error is thrown
+- When the input is an auto-increment column or a generated column, an error
is thrown
+
+[Doris-supported default value related
parameters](../../../sql-statements/table-and-view/table/CREATE-TABLE.md#Column-Default-Value-Related-Parameters)
+
+## Examples
+
+1. Non-aggregate types with constant default values
+```sql
+-- setup
+-- Columns without an explicitly defined DEFAULT accept only NULL as the
default value
+-- ARRAY type default values only accept `[]` and NULL
+CREATE TABLE test_default_scalar (
+ c_bool BOOLEAN NULL
DEFAULT 1,
+ c_tinyint TINYINT NULL
DEFAULT 7,
+ c_smallint SMALLINT NULL
DEFAULT 32000,
+ c_int INT NULL
DEFAULT 2147483647,
+ c_bigint BIGINT NULL
DEFAULT 9223372036854775807,
+ c_largeint LARGEINT NULL
DEFAULT '170141183460469231731687303715884105727',
+ c_float FLOAT NULL
DEFAULT 3.125,
+ c_double DOUBLE NULL
DEFAULT 2.718281828,
+ c_decimal DECIMAL(27, 9) NULL
DEFAULT '123456789.123456789',
+ c_decimal_compact DECIMAL(18, 4) NULL
DEFAULT '99999.1234',
+ c_pi DOUBLE NULL
DEFAULT PI,
+ c_e DOUBLE NULL
DEFAULT E,
+ c_char CHAR(8) NULL
DEFAULT 'charDemo',
+ c_varchar VARCHAR(32) NULL
DEFAULT '',
+ c_string STRING NULL
DEFAULT 'plain string',
+ c_datetime DATETIME NULL
DEFAULT '2025-10-25 11:22:33',
+ c_date DATE NULL
DEFAULT '2025-10-31',
+ c_json JSON NULL,
+ c_ipv4 IPV4 NULL
DEFAULT '192.168.1.1',
+ c_ipv6 IPV6 NULL
DEFAULT '2001:db8::1',
+ c_array_int ARRAY<INT> NULL
DEFAULT '[]',
+ c_array_string ARRAY<STRING> NULL,
+ c_map_str_int MAP<STRING, INT> NULL,
+ c_struct STRUCT<f1:INT,f2:STRING,f3:BOOLEAN> NULL,
+ c_variant VARIANT NULL
+) PROPERTIES ( 'replication_num' = '1');
+
+-- INSERT statements omitted in the example
+SELECT
+ DEFAULT(c_bool),
+ DEFAULT(c_tinyint),
+ DEFAULT(c_smallint),
+ DEFAULT(c_int),
+ DEFAULT(c_bigint),
+ DEFAULT(c_largeint),
+ DEFAULT(c_float),
+ DEFAULT(c_double),
+ DEFAULT(c_decimal),
+ DEFAULT(c_decimal_compact),
+ DEFAULT(c_pi),
+ DEFAULT(c_e),
+ DEFAULT(c_char),
+ DEFAULT(c_varchar),
+ DEFAULT(c_string),
+ DEFAULT(c_datetime),
+ DEFAULT(c_date),
+ DEFAULT(c_json),
+ DEFAULT(c_ipv4),
+ DEFAULT(c_ipv6),
+ DEFAULT(c_array_int),
+ DEFAULT(c_array_string),
+ DEFAULT(c_map_str_int),
+ DEFAULT(c_struct),
+ DEFAULT(c_variant)
+FROM test_default_scalar
+LIMIT 1;
+```
+```text
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+| DEFAULT(c_bool) | DEFAULT(c_tinyint) | DEFAULT(c_smallint) | DEFAULT(c_int)
| DEFAULT(c_bigint) | DEFAULT(c_largeint) |
DEFAULT(c_float) | DEFAULT(c_double) | DEFAULT(c_decimal) |
DEFAULT(c_decimal_compact) | DEFAULT(c_pi) | DEFAULT(c_e) |
DEFAULT(c_char) | DEFAULT(c_varchar) | DEFAULT(c_string) | DEFAULT(c_datetime)
| DEFAULT(c_date) | DEFAULT(c_json) | DEFAULT(c_ipv4) | DEFAULT(c_ipv6) |
DEFAULT(c_array_int) | DEFAULT(c_array_string) | DEFAULT(c_map_st [...]
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+| 1 | 7 | 32000 | 2147483647
| 9223372036854775807 | 170141183460469231731687303715884105727 |
3.125 | 2.718281828 | 123456789.123456789 | 99999.1234 |
3.141592653589793 | 2.718281828459045 | charDemo | |
plain string | 2025-10-25 11:22:33 | 2025-10-31 | NULL |
192.168.1.1 | 2001:db8::1 | [] | NULL
| NULL [...]
++-----------------+--------------------+---------------------+----------------+---------------------+-----------------------------------------+------------------+-------------------+---------------------+----------------------------+-------------------+-------------------+-----------------+--------------------+-------------------+---------------------+-----------------+-----------------+-----------------+-----------------+----------------------+-------------------------+-----------------
[...]
+```
+
+2. Aggregate types example
+```sql
+CREATE TABLE test_default_agg (
+ k_id INT NOT NULL COMMENT 'aggregation key',
+ bitmap_col BITMAP BITMAP_UNION,
+ hll_col HLL HLL_UNION,
+ quantile_col QUANTILE_STATE QUANTILE_UNION
+) AGGREGATE KEY(k_id)
+PROPERTIES ( 'replication_num' = '1' );
+
+SELECT
+ default(bitmap_col),default(hll_col)
+FROM test_default_agg
+LIMIT 1;
+```
+```text
++---------------------+------------------+
+| default(bitmap_col) | default(hll_col) |
++---------------------+------------------+
+| NULL | NULL |
++---------------------+------------------+
+```
+
+3. Non-constant defaults (`CURRENT_TIMESTAMP`, `CURRENT_DATE`) example:
+```sql
+CREATE TABLE test_default_time(
+ tm DATETIME(5) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
+ dt DATE DEFAULT CURRENT_DATE
+) PROPERTIES( 'replication_num' = '1' );
+
+SELECT DEFAULT(tm), DEFAULT(dt) FROM test_default_time;
+```
+```text
++---------------------------+-------------+
+| DEFAULT(tm) | DEFAULT(dt) |
++---------------------------+-------------+
+| 2026-01-23 17:32:10.90500 | 2026-01-23 |
++---------------------------+-------------+
+```
+
+4. Constant values
+```sql
+SELECT DEFAULT('hello');
+-- ERROR 1105 (HY000): errCode = 2, detailMessage =
+-- mismatched input ''hello'' expecting {'{', '}', 'ACTIONS', 'AFTER',
'AGG_STATE', 'AGGREGATE', 'ALIAS', 'ANALYZED', 'ARRAY', 'AT', 'AUTHORS',
'AUTO_INCREMENT', 'ALWAYS', 'BACKENDS', 'BACKUP', 'BEGIN', 'BELONG', 'BIN',
'BITAND', 'BITMAP', 'BITMAP_EMPTY', 'BITMAP_UNION', 'BITOR', 'BITXOR', 'BLOB',
'BOOLEAN', 'BRANCH', 'BRIEF', 'BROKER', 'BUCKETS', 'BUILD', 'BUILTIN', 'CACHE',
'CACHED', 'CALL', 'CATALOG', 'CATALOGS', 'CHAIN', CHAR, 'CHARSET', 'CHECK',
'CLUSTER', 'CLUSTERS', 'COLLA
+
+SELECT DEFAULT(NULL);
+-- ERROR 1105 (HY000): errCode = 2, detailMessage =
+-- mismatched input 'NULL' expecting {'{', '}', 'ACTIONS', 'AFTER',
'AGG_STATE', 'AGGREGATE', 'ALIAS', 'ANALYZED', 'ARRAY', 'AT', 'AUTHORS',
'AUTO_INCREMENT', 'ALWAYS', 'BACKENDS', 'BACKUP', 'BEGIN', 'BELONG', 'BIN',
'BITAND', 'BITMAP', 'BITMAP_EMPTY', 'BITMAP_UNION', 'BITOR', 'BITXOR', 'BLOB',
'BOOLEAN', 'BRANCH', 'BRIEF', 'BROKER', 'BUCKETS', 'BUILD', 'BUILTIN', 'CACHE',
'CACHED', 'CALL', 'CATALOG', 'CATALOGS', 'CHAIN', CHAR, 'CHARSET', 'CHECK',
'CLUSTER', 'CLUSTERS', 'COLLATIO
+```
+
+5. Auto-increment column
+```sql
+CREATE TABLE test_auto_inc (
+ id BIGINT NULL AUTO_INCREMENT,
+ value BIGINT NOT NULL
+) PROPERTIES ('replication_num' = '1' );
+
+INSERT INTO test_auto_inc(value) VALUES (1), (2);
+--ERROR 1105 (HY000): errCode = 2, detailMessage = Column 'id' has no default
value and does not allow NULL or column is auto-increment
+```
+
+6. Generated column
+```sql
+CREATE TABLE test_gen_col (
+ a INT,
+ b INT AS (a + 10)
+) PROPERTIES ('replication_num' = '1' );
+
+SELECT DEFAULT(b) FROM test_gen_col;
+-- ERROR 1105 (HY000): errCode = 2, detailMessage = DEFAULT cannot be used on
generated column 'b'
+```
diff --git a/versioned_sidebars/version-4.x-sidebars.json
b/versioned_sidebars/version-4.x-sidebars.json
index 621bb5154f9..5f1426eae6a 100644
--- a/versioned_sidebars/version-4.x-sidebars.json
+++ b/versioned_sidebars/version-4.x-sidebars.json
@@ -1808,6 +1808,7 @@
"label": "Other Functions",
"items": [
"sql-manual/sql-functions/scalar-functions/other-functions/convert-to",
+
"sql-manual/sql-functions/scalar-functions/other-functions/default",
"sql-manual/sql-functions/scalar-functions/other-functions/esquery",
"sql-manual/sql-functions/scalar-functions/other-functions/field",
"sql-manual/sql-functions/scalar-functions/other-functions/g",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]