-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: support expressions as ON CONFLICT targets #67893
Copy link
Copy link
Open
cockroachdb/activerecord-cockroachdb-adapter
#250Labels
A-sql-optimizerSQL logical planning and optimizations.SQL logical planning and optimizations.A-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLA-sql-syntaxIssues strictly related to the SQL grammar, with no semantic aspectIssues 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)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-queriesSQL Queries TeamSQL Queries Teamdocs-donedocs-known-limitation
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-sql-optimizerSQL logical planning and optimizations.SQL logical planning and optimizations.A-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLA-sql-syntaxIssues strictly related to the SQL grammar, with no semantic aspectIssues 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)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-queriesSQL Queries TeamSQL Queries Teamdocs-donedocs-known-limitation
Type
Projects
Status
Backlog