This document describes how Hologres handles default values when writing data across different scenarios: SQL, Flink, and Data Integration of DataWorks.
Baseline rule: If no default value is configured for a field and no value is supplied during a write operation, the system fills NULL. The tables and sections below describe how this baseline changes depending on your write path and parameters.
Behavior summary
The following table summarizes default value behavior across all write paths. Use it to quickly identify the expected behavior before diving into the details.
| Write path | Field type | Default value configured? | Behavior |
|---|---|---|---|
| SQL | Nullable | Yes | Fills the default value (if field is omitted) |
| SQL | Nullable | No | Fills NULL |
| SQL | Non-null | Yes | Fills the default value (if field is omitted) |
| Flink — JDBC mode | Nullable | No | Fills NULL |
| Flink — JDBC mode | Nullable | Yes | Fills the default value if mutatetype=InsertOrUpdate; otherwise fills NULL |
| Flink — JDBC mode | Non-null | No | Reports an error if EnableDefaultForNotNullColumn=false; fills a data type-based default if true |
| Flink — JDBC mode | Non-null | Yes | Fills the default value (Hologres engine calculates it); in versions earlier than V2.0, this may prevent fixed plans from being used |
| Flink — Fixed copy mode | Nullable | No | Fills NULL |
| Flink — Fixed copy mode | Nullable | Yes | Fills the default value |
| Flink — Fixed copy mode | Non-null | No | Reports an error |
| Flink — Fixed copy mode | Non-null | Yes | Fills the default value |
| Flink — BulkLoad mode (HQEcopy) | Nullable | No | Fills NULL |
| Flink — BulkLoad mode (HQEcopy) | Nullable | Yes | Fills the default value |
| Flink — BulkLoad mode (HQEcopy) | Non-null | No | Reports an error |
| Flink — BulkLoad mode (HQEcopy) | Non-null | Yes | Fills the default value |
| DataWorks — DataX batch | Nullable | No | Fills NULL |
| DataWorks — DataX batch | Nullable | Yes, conflictMode=Replace | Fills NULL |
| DataWorks — DataX batch | Nullable | Yes, conflictMode=Update | Fills the default value |
| DataWorks — DataX batch | Non-null | No, default.enable=true (default) | Fills a data type-based default (e.g., "" or 0) |
| DataWorks — DataX batch | Non-null | No, default.enable=false | Reports an error |
| DataWorks — DataX batch | Non-null | Yes, default.enable=true (default) | Fills the default value |
| DataWorks — DataX batch | Non-null | Yes, default.enable=false | Fills the default value; in versions earlier than V2.0, fixed plans may fail |
| DataWorks — StreamX real-time | Nullable | No | Fills NULL |
| DataWorks — StreamX real-time | Nullable | Yes, conflictMode=Replace or Ignore | Fills NULL |
| DataWorks — StreamX real-time | Nullable | Yes, conflictMode=Update | Fills the default value |
| DataWorks — StreamX real-time | Non-null | No, default.enable=true (default) | Fills a data type-based default (e.g., "" or 0) |
| DataWorks — StreamX real-time | Non-null | No, default.enable=false | Reports an error |
| DataWorks — StreamX real-time | Non-null | Yes, default.enable=true (default) | Fills the default value |
| DataWorks — StreamX real-time | Non-null | Yes, default.enable=false | Fills the default value; in versions earlier than V2.0, fixed plans may fail |
SQL scenarios
If a default value is configured for a field and no value is specified in a write or update operation, Hologres automatically fills the default value for that field.
The following examples use this table:
BEGIN;
CREATE TABLE default_test (
a int NOT NULL DEFAULT 2023,
b timestamptz DEFAULT '2023-11-17 10:11:33.276+08',
PRIMARY KEY (a)
);
COMMIT;Example 1: Specify values for both columns. The specified values overwrite the defaults.
-- Specify values for column a and column b.
INSERT INTO default_test VALUES (1, NULL);
-- Query the table.
SELECT * FROM default_test;Result:
a b
1 \NExample 2: Omit column b. The system fills the default value for column b.
-- Omit column b.
INSERT INTO default_test (a) VALUES (2);
-- Query the table.
SELECT * FROM default_test;Result:
a b
1 \N
2 2023-11-17 10:11:33.276+08Example 3: Run INSERT ON CONFLICT DO NOTHING without specifying column a (the primary key). The system writes the value for column b and fills the default value for column a.
-- Column a is omitted; the system fills the default value (2023).
INSERT INTO default_test (b) VALUES ('2023-11-18 10:11:33.276+08') ON CONFLICT (a) DO NOTHING;
-- Query the table.
SELECT * FROM default_test;Result:
a b
2 2023-11-17 10:11:33.276+08
2023 2023-11-18 10:11:33.276+08
1 \NExample 4: Run INSERT ON CONFLICT DO UPDATE with explicit values for both columns. The specified values overwrite the defaults.
-- Specify values for both columns; specified values take precedence.
INSERT INTO default_test (a, b) VALUES (2, null) ON CONFLICT (a) DO UPDATE SET (a,b) = ROW(EXCLUDED.*);
-- Query the table.
SELECT * FROM default_test;Result:
a b
1 \N
2023 2023-11-18 10:11:33.276+08
2 \NExample 5: Run INSERT ON CONFLICT DO UPDATE updating only column b. Column a is not updated.
-- Only column b is updated; column a remains unchanged.
INSERT INTO default_test (a, b) VALUES (2023, null) ON CONFLICT (a) DO UPDATE SET b = EXCLUDED.b;
-- Query the table.
SELECT * FROM default_test;Result:
a b
2 \N
1 \N
2023 \NWrite data using Flink
For more information about Flink write modes, see Hologres.
JDBC mode
The following rules apply to fields for which no values are specified.
Nullable fields
No default value configured: the system fills NULL.
Default value configured: the system fills the default value if
mutatetypeis set toInsertOrUpdate; otherwise, the system fills NULL.
Non-null fields
No default value configured:
EnableDefaultForNotNullColumn=false: the system reports an error.EnableDefaultForNotNullColumn=true: Holo Client fills a data type-based default (for example, an empty string"").
Default value configured:
EnableDefaultForNotNullColumn=false: the Hologres engine calculates and writes the default value. In Hologres versions earlier than V2.0, this may prevent fixed plans from being used and cause performance issues.EnableDefaultForNotNullColumn=true: Holo Client fills a data type-based default.
You can manually upgrade your Hologres instance or join the Hologres DingTalk group to apply for an upgrade. For more information, see the "Manual upgrade" section in Upgrade an instance. To get online support, see Obtain online support for Hologres.
Fixed copy mode
Only UPDATE and IGNORE operations are supported in this mode. When you update specific fields, only those fields are updated; all other fields remain unchanged. To achieve a REPLACE effect, declare all fields in the Flink DDL statement.
The following rules apply to fields for which no values are specified.
Nullable fields
No default value configured: the system fills NULL.
Default value configured: the system fills the default value.
Non-null fields
No default value configured: the system reports an error.
Default value configured: the system fills the default value.
BulkLoad mode (HQEcopy)
UPDATE operations are not supported in this mode. The following rules apply to fields for which no values are specified.
Nullable fields
No default value configured: the system fills NULL.
Default value configured: the system fills the default value.
Non-null fields
No default value configured: the system reports an error.
Default value configured: the system fills the default value.
Write data using Data Integration of DataWorks
DataX-based batch synchronization
DataX of Data Integration supports batch synchronization from a table or a database. For more information, see Hologres data source. JDBC mode is used automatically. The following rules apply to fields for which no values are specified.
Nullable fields
No default value configured: the system fills NULL.
Default value configured:
conflictMode=Replace: the system fills NULL.conflictMode=Update: the system fills the default value.
Non-null fields
No default value configured:
default.enable=true(default): Holo Client fills a data type-based default (for example, an empty string""or0).default.enable=false: the system reports an error.
Default value configured:
default.enable=true(default): the system fills the default value.default.enable=false: the system also fills the default value. In Hologres versions earlier than V2.0, fixed plans may fail to be used, and performance issues may occur.
StreamX-based real-time synchronization
StreamX of Data Integration supports real-time synchronization from a table. For more information, see Hologres data source. JDBC mode is used automatically. The following rules apply to fields for which no values are specified.
Nullable fields
No default value configured: the system fills NULL.
Default value configured:
conflictMode=ReplaceorconflictMode=Ignore: the system fills NULL.conflictMode=Update: the system fills the default value.
Non-null fields
No default value configured:
default.enable=true(default): Holo Client fills a data type-based default (for example, an empty string""or0).default.enable=false: the system reports an error.
Default value configured:
default.enable=true(default): the system fills the default value.default.enable=false: the system also fills the default value. In Hologres versions earlier than V2.0, fixed plans may fail to be used, and performance issues may occur.
You can manually upgrade your Hologres instance or join the Hologres DingTalk group to apply for an upgrade. For more information, see the "Manual upgrade" section in Upgrade an instance. To get online support, see Obtain online support for Hologres.
Holo Client default value mapping
When you use Flink or Data Integration of DataWorks to write data in JDBC mode, Holo Client handles the write layer. If you specify values for specific fields when you write data, the default.enable parameter is automatically set to true (equivalent to enableDefaultForNotNullColumn=true). If a field has no value and no configured default, Holo Client fills a data type-based default automatically. The following table lists these defaults.
| Type | Default filled by Holo Client |
|---|---|
| SMALLINT | 0 |
| INTEGER | 0 |
| BIGINT | 0 |
| REAL | 0.0 |
| DOUBLE PRECISION | 0.0 |
| DECIMAL | 0 |
| BOOLEAN | false |
| VARCHAR(n) | "" (empty string) |
| CHAR(n) | "" (empty string) |
| TEXT | "" (empty string) |
| TIMESTAMPTZ | 1970-01-01 08:00:00 |
| TIMESTAMP | 1970-01-01 08:00:00 |
| DATE | 1970-01-01 |
| TIMETZ | 08:00:00 |
| TIME | 08:00:00 |
| JSON and JSONB | Cannot write a default value |
| BYTEA | Cannot write a default value |
| RoaringBitmap | Cannot write a default value |
| BIT(n) | Cannot write a default value |
| VARBIT(n) | Cannot write a default value |
| INTERVAL | Cannot write a default value |