Skip to content

Please support excluded table in INSERT ... ON CONFLICT ... WHERE predicate #1111

Closed
@dlurton

Description

@dlurton

Relevant Issue/Bug

I list this as a feature, not a bug, because it seems clear that this is work as yet undone, instead of incorrect behavior of completed code. #1061 implemented support for the WHERE clause, but did not include support for the excluded table.

Requested Solution/Feature

Two problems are preventing the excluded table from working today:

Parse Error

I would expect that this query parse correctly:

INSERT INTO foo AS f << {'id': 1, 'version': 42} >> 
ON CONFLICT DO REPLACE EXCLUDED 
WHERE foo.version < excluded.version

... but I receive the following exception:

org.partiql.lang.syntax.ParserException: mismatched input 'WHERE' expecting {<EOF>, ';'}
	Parser Error: at line 1, column 69: unexpected token found, WHERE : WHERE

On experimentation, I found that this error happens any time the keyword excluded is included in the WHERE clause. (Parsing succeeds if excluded.version is replaced with whatever.bar). On inspection of PartiQL.g4 it appears that EXCLUDED is not treated as an expression.

Variable Resolution

The excluded variable must be added to the local scope for variable resolution within the WHERE clause. Without this, any reference to the excluded table will be reported as an undefined variable.

Describe Alternatives

AFAIK there are no alternatives.

Additional Context

My team intends to use the excluded table in the very near future. The workaround is to use parameters and reference them instead of the excluded table, but this will only work when inserting a single record. We would like to support multi-record inserts.

INSERT INTO foo AS f << {'id': $id, version: $version } >> 
ON CONFLICT DO REPLACE EXCLUDED 
WHERE foo.version < $version

DoD (Definition of Done)

  • The excluded table can be referenced in the WHERE clause of INSERT INTO ... ON CONFLICT ... WHERE... without causing any errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions