Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support expr in values clause of multi table insert #15147

Merged
merged 12 commits into from
Apr 2, 2024

Conversation

SkyFan2002
Copy link
Member

@SkyFan2002 SkyFan2002 commented Apr 1, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

  1. Improved syntax:
intoClause ::=
  INTO <target_table> [ ( <target_col_name> [ , ... ] ) ] [VALUES( { Expr | DEFAULT } [ , ... ] ) ]
  1. Deal with default ambiguity
    While in snowflake DEFAULT(represents a default value) and a ident named default is ambiguous:
    snowflake

in our implemention the column name in source of multi-table insert can't be default:

:) create or replace table t1(c1 int,c2 int);

CREATE
OR REPLACE TABLE t1(c1 int, c2 int)

:) create or replace table t2(c1 int,c2 int);

CREATE
OR REPLACE TABLE t2(c1 int, c2 int)

:) create or replace table s(c3 int,default int);

CREATE
OR REPLACE TABLE s(c3 int, DEFAULT int)

:) insert into s values(1,2),(3,4),(5,6);

INSERT INTO
  s
VALUES
(1, 2),
(3, 4),
(5, 6)

3 rows written in 0.112 sec. Processed 3 rows, 26 B (26.82 rows/s, 232 B/s)

:) INSERT FIRST
    WHEN c3 = 5 THEN
      INTO t1
    WHEN c3 > 0 THEN
      INTO t2 values(c3, default)
SELECT * from s;
error: APIError: ResponseError with 1006: The column name in source of multi-table insert can't be 'default'

It is recommended to use aliases to bypass this restriction:

INSERT FIRST
    WHEN c3 = 5 THEN
      INTO t1
    WHEN c3 > 0 THEN
      INTO t2 values(c3, c4)
SELECT c3,default as c4 from s;


Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Apr 1, 2024
@SkyFan2002 SkyFan2002 marked this pull request as ready for review April 1, 2024 12:12
Copy link
Member

@dantengsky dantengsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/query/sql/src/executor/format.rs Outdated Show resolved Hide resolved
src/query/sql/src/executor/physical_plan_display.rs Outdated Show resolved Hide resolved
SkyFan2002 and others added 2 commits April 2, 2024 18:00
Co-authored-by: dantengsky <dantengsky@gmail.com>
Co-authored-by: dantengsky <dantengsky@gmail.com>
@dantengsky dantengsky added this pull request to the merge queue Apr 2, 2024
@BohuTANG BohuTANG removed this pull request from the merge queue due to a manual request Apr 2, 2024
@BohuTANG BohuTANG merged commit f1fd67a into databendlabs:main Apr 2, 2024
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants