-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Default expressions in INSERT query #51509
Copy link
Copy link
Open
Labels
Description
Use case
Specify an expression, or at least a constant, in the INSERT query that will be used instead of the input data.
Describe the solution you'd like
We should support two use cases:
- When an expression is specified instead of providing a column in the inserted data;
- When an expression is specified as a default value, but the column is still parsed from the inserted data, but the values can be omitted in certain records (e.g., from JSONEachRow format or DEFAULT in the Values format).
The first use case is more important.
I'm not sure what syntax is better for that and what are the alternatives in other databases:
INSERT INTO t (c1, c2, 'Hello' AS c3, now() AS c4) ...
INSERT INTO t (c1, c2, c3 DEFAULT 'Hello', c4 MATERIALIZED now()) ...
INSERT INTO t (c1, c2, c3 DEFAULT 'Hello', c4 = now()) ...
Describe alternatives you've considered
It is already possible with INSERT ... SELECT FROM input, just slightly more cumbersome, but more versatile:
INSERT INTO t SELECT c1, c2, c3, 'Hello' AS c4 FROM input('c1 UInt8, c2 String, c3 String, c4 DateTime DEFAULT now())
PS. Please find duplicate issues in the repository and link here.
Reactions are currently unavailable