cockroachdb / cockroachdb/cockroach

add hints on syntax error on returning clause with exclude

Open
#101,347 2 comments 0 reactions 0 assignees View on GitHub
C-enhancement O-community T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Is your feature request related to a problem? Please describe.**
we have experiment with a syntax incorrect query
```
INSERT INTO "test" ("a","b","c") VALUES (1,2,3) ON CONFLICT ("a") DO UPDATE SET "b"=excluded."b","c"=excluded."c" RETURNING ("a" != excluded."a") AS "$CREATED","a","b","c";
```
we have multiple occurrences of the exclude in this statement. The postgres hint is super informative and pin point to the problem.

this is the crdb result
```
ERROR: no data source matches prefix: excluded in this context
SQLSTATE: 42P01
```

**Describe the solution you'd like**
it would be awesome to add a hint on this like postgres.
```
postgres=# INSERT INTO "test" ("a","b","c") VALUES (1,2,3) ON CONFLICT ("a") DO UPDATE SET "b"=excluded."b","c"=excluded."c" RETURNING ("a" != excluded."a") AS "$CREATED","a","b","c";
ERROR: invalid reference to FROM-clause entry for table "excluded"
LINE 1: ..."=excluded."b","c"=excluded."c" RETURNING ("a" != excluded."...
^
HINT: There is an entry for table "excluded", but it cannot be referenced from this part of the query
```

Jira issue: CRDB-26907

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.