Skip to content

Feature: support async function for merge not match clause #17936

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

Closed
zhang2014 opened this issue May 14, 2025 · 0 comments · Fixed by #17941
Closed

Feature: support async function for merge not match clause #17936

zhang2014 opened this issue May 14, 2025 · 0 comments · Fixed by #17941
Assignees
Labels
C-feature Category: feature

Comments

@zhang2014
Copy link
Member

Issue Summary

Problem:
When executing a MERGE statement with an async function in the "NOT MATCHED" clause, the query fails with an index out of bounds error.

Steps to Reproduce:

  1. Create sequence:
CREATE SEQUENCE test_seq;
  1. Create target and source tables:
    CREATE TABLE target_table (id int default nextval(test_seq), name varchar(50), value int);
    CREATE TABLE source_table (id INT, name VARCHAR(50), value INT);
  2. Insert data into the source table:
    INSERT INTO source_table (name, value) VALUES ('Item1', 100);
  3. Execute the MERGE statement:
    MERGE INTO target_table AS target 
    USING source_table AS source 
    ON target.id = source.id 
    WHEN MATCHED THEN 
       UPDATE SET target.name = source.name, target.value = source.value 
    WHEN NOT MATCHED THEN 
       INSERT (name, value) VALUES (source.name, source.value);

Observed Error:

APIError: QueryFailed: [1104] index out of bounds: the len is 2 but the index is 18446744073709551610

Expected Behavior:
The MERGE statement should execute successfully, inserting or updating records as specified.

Root Cause:
The databend does not properly support async functions (e.g., sequence nextval()) in the NOT MATCHED clause of MERGE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants