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
15 changes: 0 additions & 15 deletions crates/squawk_lexer/src/snapshots/squawk_lexer__tests__floats.snap

This file was deleted.

110 changes: 84 additions & 26 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1819,29 +1819,51 @@ fn name_ref_(p: &mut Parser<'_>) -> Option<CompletedMarker> {
let m = p.start();
// TODO: this needs to be cleaned up
let mut is_interval_cast = false;
let kind = if p.eat(COLLATION_KW) {
p.expect(FOR_KW);
NAME_REF
// timestamp with time zone / time with time zone
} else if p.eat(TIMESTAMP_KW) || p.eat(TIME_KW) {
if p.eat(L_PAREN) {
if opt_numeric_literal(p).is_none() {
p.error("expected numeric literal");
let kind = match p.current() {
COLLATION_KW => {
p.bump(COLLATION_KW);
p.expect(FOR_KW);
NAME_REF
}
TIMESTAMP_KW | TIME_KW => {
p.bump_any();
if p.eat(L_PAREN) {
if opt_numeric_literal(p).is_none() {
p.error("expected numeric literal");
}
p.expect(R_PAREN);
}
p.expect(R_PAREN);
if p.eat(WITH_KW) || p.eat(WITHOUT_KW) {
p.expect(TIME_KW);
p.expect(ZONE_KW);
}
TIME_TYPE
}
if p.eat(WITH_KW) {
p.expect(TIME_KW);
p.expect(ZONE_KW);
BIT_KW => {
p.bump(BIT_KW);
p.eat(VARYING_KW);
BIT_TYPE
}
NATIONAL_KW if matches!(p.nth(1), CHAR_KW | CHARACTER_KW) => {
p.bump(NATIONAL_KW);
char_type(p)
}
DOUBLE_KW if p.nth_at(1, PRECISION_KW) => {
p.bump(DOUBLE_KW);
p.bump(PRECISION_KW);
DOUBLE_TYPE
}
CHARACTER_KW | CHAR_KW | NCHAR_KW | VARCHAR_KW => char_type(p),
INTERVAL_KW => {
p.bump(INTERVAL_KW);
opt_interval_trailing(p);
is_interval_cast = true;
INTERVAL_TYPE
}
_ => {
p.bump_any();
NAME_REF
}
TIME_TYPE
} else if p.eat(INTERVAL_KW) {
opt_interval_trailing(p);
is_interval_cast = true;
INTERVAL_TYPE
} else {
p.bump_any();
NAME_REF
};
let cm = m.complete(p, if p.at(STRING) { kind } else { NAME_REF });

Expand Down Expand Up @@ -10920,7 +10942,7 @@ fn create_view(p: &mut Parser<'_>) -> CompletedMarker {
},
) {
Some(statement) => match statement.kind() {
SELECT | COMPOUND_SELECT | SELECT_INTO => (),
SELECT | COMPOUND_SELECT | SELECT_INTO | VALUES | TABLE => (),
kind => p.error(format!("expected SELECT, got {:?}", kind)),
},
None => p.error("expected SELECT"),
Expand Down Expand Up @@ -11033,8 +11055,26 @@ fn reset(p: &mut Parser<'_>) -> CompletedMarker {
assert!(p.at(RESET_KW));
let m = p.start();
p.bump(RESET_KW);
if !p.eat(ALL_KW) {
path_name_ref(p);
match p.current() {
ALL_KW => {
p.bump(ALL_KW);
}
SESSION_KW => {
p.bump(SESSION_KW);
p.expect(AUTHORIZATION_KW);
}
TRANSACTION_KW => {
p.bump(TRANSACTION_KW);
p.expect(ISOLATION_KW);
p.expect(LEVEL_KW);
}
TIME_KW => {
p.bump(TIME_KW);
p.expect(ZONE_KW);
}
_ => {
path_name_ref(p);
}
}
m.complete(p, RESET)
}
Expand Down Expand Up @@ -12945,8 +12985,26 @@ fn show(p: &mut Parser<'_>) -> CompletedMarker {
assert!(p.at(SHOW_KW));
let m = p.start();
p.bump(SHOW_KW);
if !p.eat(ALL_KW) {
path_name_ref(p);
match p.current() {
ALL_KW => {
p.bump(ALL_KW);
}
SESSION_KW => {
p.bump(SESSION_KW);
p.expect(AUTHORIZATION_KW);
}
TRANSACTION_KW => {
p.bump(TRANSACTION_KW);
p.expect(ISOLATION_KW);
p.expect(LEVEL_KW);
}
TIME_KW => {
p.bump(TIME_KW);
p.expect(ZONE_KW);
}
_ => {
path_name_ref(p);
}
}
m.complete(p, SHOW)
}
Expand Down Expand Up @@ -13268,7 +13326,7 @@ fn alter_table_action(p: &mut Parser<'_>) -> Option<SyntaxKind> {
p.bump(DETACH_KW);
p.expect(PARTITION_KW);
// partition_name
name_ref(p);
path_name_ref(p);
// [ CONCURRENTLY | FINALIZE ]
if !p.eat(CONCURRENTLY_KW) {
p.eat(FINALIZE_KW);
Expand Down
4 changes: 4 additions & 0 deletions crates/squawk_parser/tests/data/ok/reset.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
reset some_config_param;
reset all;

reset foo.bar.buzz;
reset time zone;
reset transaction isolation level;
reset session authorization;
57 changes: 57 additions & 0 deletions crates/squawk_parser/tests/data/ok/select_casts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,60 @@ select cast(a as foo.bar);
select treat(a as foo.b);
select treat('1231' as numeric);

-- prefix
select json '{}';

select timestamp(4) '';
select timestamp '';

select time(4) '';
select time '';

select character varying '';
select character '';
select char varying '';
select char '';
select varchar '';
select national character varying '';
select national character '';
select national char varying '';
select national char '';
select nchar varying '';
select nchar '';

select character varying(10) '';
select character(10) '';
select char varying(10) '';
select char(10) '';
select varchar(10) '';
select national character varying(10) '';
select national character(10) '';
select national char varying(10) '';
select national char(10) '';
select nchar varying(10) '';
select nchar(10) '';

select bit varying(10) '';
select bit(10) '';

select bit varying '';
select bit '';

select int '';
select integer '';
select smallint '';
select bigint '';
select real '';
select float '';
select float(8) '';
select double precision '';
select decimal(10, 2) '10';
select decimal '10';
select dec(10, 2) '10';
select dec '10';
select numeric(10, 2) '10';
select numeric '10';
select boolean 'false';

select foo.bar '100';
select foo.bar(10, 2) '100';
1 change: 1 addition & 0 deletions crates/squawk_parser/tests/data/ok/select_casts_pg17.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select foo[10].bar(10, 2) '100';
8 changes: 8 additions & 0 deletions crates/squawk_parser/tests/data/ok/show.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
show time zone;
show transaction isolation level;
show session authorization;
show all;

show v;
show a.b;
show a.b.c.d;
22 changes: 11 additions & 11 deletions crates/squawk_parser/tests/data/regression_suite/groupingsets.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ create temp view gstest1(a,b,v)
create temp table gstest2 (a integer, b integer, c integer, d integer,
e integer, f integer, g integer, h integer);
copy gstest2 from stdin;
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 2
1 1 1 1 1 1 2 2
1 1 1 1 1 2 2 2
1 1 1 1 2 2 2 2
1 1 1 2 2 2 2 2
1 1 2 2 2 2 2 2
1 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2
-- 1 1 1 1 1 1 1 1
-- 1 1 1 1 1 1 1 2
-- 1 1 1 1 1 1 2 2
-- 1 1 1 1 1 2 2 2
-- 1 1 1 1 2 2 2 2
-- 1 1 1 2 2 2 2 2
-- 1 1 2 2 2 2 2 2
-- 1 2 2 2 2 2 2 2
-- 2 2 2 2 2 2 2 2

create temp table gstest3 (a integer, b integer, c integer, d integer);
copy gstest3 from stdin;
1 1 1 1
2 2 2 2
-- 1 1 1 1
-- 2 2 2 2
alter table gstest3 add primary key (a);

create temp table gstest4(id integer, v integer,
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_parser/tests/data/regression_suite/rules.sql
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ select * from rtest_v1;
insert into rtest_v1 values (2, 12);
insert into rtest_v1 values (2, 13);
select * from rtest_v1;
** Remember the delete rule on rtest_v1: It says
** DO INSTEAD DELETE FROM rtest_t1 WHERE a = old.a
** So this time both rows with a = 2 must get deleted
-- ** Remember the delete rule on rtest_v1: It says
-- ** DO INSTEAD DELETE FROM rtest_t1 WHERE a = old.a
-- ** So this time both rows with a = 2 must get deleted
delete from rtest_v1 where b = 12;
select * from rtest_v1;
delete from rtest_v1;
Expand Down
18 changes: 12 additions & 6 deletions crates/squawk_parser/tests/snapshots/tests__alter_table_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3692,8 +3692,10 @@ SOURCE_FILE
WHITESPACE " "
PARTITION_KW "partition"
WHITESPACE " "
NAME_REF
IDENT "f"
PATH
PATH_SEGMENT
NAME_REF
IDENT "f"
SEMICOLON ";"
WHITESPACE "\n\n"
COMMENT "-- concurrently"
Expand All @@ -3714,8 +3716,10 @@ SOURCE_FILE
WHITESPACE " "
PARTITION_KW "partition"
WHITESPACE " "
NAME_REF
IDENT "f"
PATH
PATH_SEGMENT
NAME_REF
IDENT "f"
WHITESPACE " "
CONCURRENTLY_KW "concurrently"
SEMICOLON ";"
Expand All @@ -3738,8 +3742,10 @@ SOURCE_FILE
WHITESPACE " "
PARTITION_KW "partition"
WHITESPACE " "
NAME_REF
IDENT "f"
PATH
PATH_SEGMENT
NAME_REF
IDENT "f"
WHITESPACE " "
FINALIZE_KW "finalize"
SEMICOLON ";"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@
source: crates/squawk_parser/tests/tests.rs
input_file: crates/squawk_parser/tests/data/regression_suite/foreign_key.sql
---
ERROR@65605: expected SEMICOLON
ERROR@65605: expected command, found DOT
ERROR@65606: expected command, found IDENT
ERROR@66561: expected SEMICOLON
ERROR@66561: expected command, found DOT
ERROR@66562: expected command, found IDENT

Loading
Loading