Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,11 +877,7 @@ fn exists_fn(p: &mut Parser<'_>) -> CompletedMarker {
let m = p.start();
p.bump(EXISTS_KW);
p.expect(L_PAREN);
if p.at_ts(SELECT_FIRST) {
select(p, None, &SelectRestrictions::default(), false);
} else {
p.error("expected select");
}
query(p);
p.expect(R_PAREN);
let m = m.complete(p, EXISTS_FN).precede(p);
opt_agg_clauses(p);
Expand Down Expand Up @@ -10024,7 +10020,7 @@ fn create_role(p: &mut Parser<'_>) -> CompletedMarker {

fn select_insert_delete_update_or_notify(p: &mut Parser<'_>, semi_allowed: bool) {
// statement
// Any SELECT, INSERT, UPDATE, DELETE, MERGE, or VALUES statement.
// Any SELECT, INSERT, UPDATE, DELETE, NOTIFY, or VALUES statement.
let statement = stmt(
p,
&StmtRestrictions {
Expand All @@ -10034,7 +10030,8 @@ fn select_insert_delete_update_or_notify(p: &mut Parser<'_>, semi_allowed: bool)
);
if let Some(statement) = statement {
match statement.kind() {
SELECT | VALUES | INSERT | UPDATE | DELETE | NOTIFY => (),
SELECT | COMPOUND_SELECT | PAREN_SELECT | TABLE | VALUES | INSERT | UPDATE | DELETE
| NOTIFY => (),
kind => {
p.error(format!(
"expected SELECT, INSERT, UPDATE, DELETE, NOTIFY, or VALUES statement, got {kind:?}"
Expand Down Expand Up @@ -11148,7 +11145,7 @@ fn explain(p: &mut Parser<'_>) -> CompletedMarker {
}

fn opt_explain_option_list(p: &mut Parser<'_>) -> Option<CompletedMarker> {
if !p.at(L_PAREN) || (p.at(L_PAREN) && p.nth_at_ts(1, SELECT_FIRST)) {
if !p.at(L_PAREN) || p.nth_at_ts(1, PAREN_SELECT_FIRST) {
return None;
}
let m = p.start();
Expand Down
10 changes: 10 additions & 0 deletions crates/squawk_parser/tests/data/ok/create_rule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ create or replace rule r as on select
notify f;
);

-- select_stmt_variants
create rule r as on insert to t do instead ((select 1));
create rule r as on insert to t do also ((select 1));
create rule r as on insert to t do instead (notify foo; (select 1););
create rule r as on insert to t do instead ((select 1) union (select 2););
create rule r as on insert to t do instead select 1 union select 2;
create rule r as on insert to t do instead (select 1 union select 2;);
create rule r as on insert to t do instead table t;
create rule r as on insert to t do instead (table t;);

-- doc_1
CREATE RULE "_RETURN" AS
ON SELECT TO t1
Expand Down
3 changes: 3 additions & 0 deletions crates/squawk_parser/tests/data/ok/explain.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ EXPLAIN (GENERIC_PLAN)

-- parens_select
explain analyze (((((select 1)))));
explain ((select 1));
explain ((select 1) union (select 2));

-- parens_values
explain analyze (((((values (1))))));
explain ((values (1)));

-- boolean off
EXPLAIN (COSTS OFF) SELECT * FROM foo WHERE i = 4;
Expand Down
4 changes: 4 additions & 0 deletions crates/squawk_parser/tests/data/ok/select_funcs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ select json_scalar(1);

-- exists
select exists(select 1 from t where a = b);
select exists((select 1));
select exists(((select 1)));
select exists((select 1) union (select 2));
select exists((table t));

select exists(with t as (select 1) select * from t);

Expand Down
Loading
Loading