Skip to content

sql: support expressions as ON CONFLICT targets #67893

@mgartner

Description

@mgartner

We don't currently support expressions as ON CONFLICT targets. This means that unique expression indexes (still a WIP at the time this was written) cannot be selected as arbiters for INSERT .. ON CONFLICT statements. This will require adding support for expression ON CONFLICT targets to the parser and the AST, and updating optbuilder's arbiter logic to select arbiters based on the expression.

Example:

defaultdb> SET experimental_enable_expression_indexes=true;
SET

defaultdb> CREATE TABLE t (a INT, b INT, UNIQUE INDEX ((a + b)));
CREATE TABLE

defaultdb> INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO NOTHING;
invalid syntax: statement ignored: at or near "(": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO NOTHING
                                         ^
HINT: try \h INSERT

defaultdb> INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO UPDATE SET a = 10;
invalid syntax: statement ignored: at or near "(": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO UPDATE SET a = 10
                                         ^
HINT: try \h INSERT

Jira issue: CRDB-8765

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-sql-optimizerSQL logical planning and optimizations.A-sql-pgcompatSemantic compatibility with PostgreSQLA-sql-syntaxIssues strictly related to the SQL grammar, with no semantic aspectA-tools-hasuraC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-queriesSQL Queries Teamdocs-donedocs-known-limitation

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions