Skip to content

Commit 1758654

Browse files
authored
parser: fix parsing insert select on conflict (#720)
We were parsing the on conflict as a join. rel: #718
1 parent 191230d commit 1758654

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

crates/squawk_parser/src/grammar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3456,7 +3456,7 @@ fn join(p: &mut Parser<'_>) {
34563456
if !opt_from_item(p) {
34573457
p.error("expected from_item");
34583458
}
3459-
if p.at(ON_KW) {
3459+
if p.at(ON_KW) && !p.nth_at(1, CONFLICT_KW) {
34603460
on_clause(p);
34613461
} else if p.at(USING_KW) {
34623462
join_using_clause(p);

crates/squawk_parser/tests/data/ok/insert.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,12 @@ INSERT INTO distributors (did, dname) VALUES (10, 'Conrad International')
9191

9292
-- with schema
9393
insert into s.t (c) values (1);
94+
95+
96+
-- regression check for issue #718
97+
-- we were parsing the `on conflict` as the start of a `join on`
98+
INSERT INTO t
99+
SELECT *
100+
FROM t
101+
CROSS JOIN f
102+
ON CONFLICT DO NOTHING;

crates/squawk_parser/tests/snapshots/tests__insert_ok.snap

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,4 +1463,55 @@ SOURCE_FILE
14631463
INT_NUMBER "1"
14641464
R_PAREN ")"
14651465
SEMICOLON ";"
1466+
WHITESPACE "\n\n\n"
1467+
COMMENT "-- regression check for issue #718"
1468+
WHITESPACE "\n"
1469+
COMMENT "-- we were parsing the `on conflict` as the start of a `join on`"
1470+
WHITESPACE "\n"
1471+
INSERT
1472+
INSERT_KW "INSERT"
1473+
WHITESPACE " "
1474+
INTO_KW "INTO"
1475+
WHITESPACE " "
1476+
PATH
1477+
PATH_SEGMENT
1478+
NAME_REF
1479+
IDENT "t"
1480+
WHITESPACE "\n"
1481+
SELECT
1482+
SELECT_CLAUSE
1483+
SELECT_KW "SELECT"
1484+
WHITESPACE " "
1485+
TARGET_LIST
1486+
TARGET
1487+
STAR "*"
1488+
WHITESPACE "\n"
1489+
FROM_CLAUSE
1490+
FROM_KW "FROM"
1491+
WHITESPACE " "
1492+
JOIN_EXPR
1493+
FROM_ITEM
1494+
NAME_REF
1495+
IDENT "t"
1496+
WHITESPACE "\n"
1497+
JOIN
1498+
JOIN_CROSS
1499+
CROSS_KW "CROSS"
1500+
WHITESPACE " "
1501+
JOIN_KW "JOIN"
1502+
WHITESPACE " "
1503+
FROM_ITEM
1504+
NAME_REF
1505+
IDENT "f"
1506+
WHITESPACE "\n"
1507+
ON_CONFLICT_CLAUSE
1508+
ON_KW "ON"
1509+
WHITESPACE " "
1510+
CONFLICT_KW "CONFLICT"
1511+
WHITESPACE " "
1512+
CONFLICT_DO_NOTHING
1513+
DO_KW "DO"
1514+
WHITESPACE " "
1515+
NOTHING_KW "NOTHING"
1516+
SEMICOLON ";"
14661517
WHITESPACE "\n"

0 commit comments

Comments
 (0)