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
54 changes: 38 additions & 16 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,6 @@ fn atom_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
p.bump(POSITIONAL_PARAM);
m.complete(p, LITERAL)
}
(VALUES_KW, _) => values(p, None),
(EXTRACT_KW, L_PAREN) => extract_fn(p),
(JSON_EXISTS_KW, L_PAREN) => json_exists_fn(p),
(JSON_ARRAY_KW, L_PAREN) => json_array_fn(p),
Expand Down Expand Up @@ -3034,7 +3033,10 @@ enum ColumnDefKind {
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [ ( column_name [, ... ] ) ]
fn opt_column_list_with(p: &mut Parser<'_>, kind: ColumnDefKind) -> bool {
if !p.at(L_PAREN) {
if !p.at(L_PAREN) ||
// we're probably at (select)
!p.nth_at_ts(1, COLUMN_FIRST)
{
return false;
}
let m = p.start();
Expand Down Expand Up @@ -3800,14 +3802,13 @@ fn col_def(p: &mut Parser<'_>, t: ColDefType) -> Option<CompletedMarker> {
// TODO: validation to check for missing types
if opt_type_name(p) {
// [ STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } ]
if p.eat(STORAGE_KW) && (p.at(DEFAULT_KW) || p.at(IDENT)) {
if p.eat(STORAGE_KW) && (p.at(DEFAULT_KW) || p.at(EXTERNAL_KW) || p.at(IDENT)) {
p.bump_any();
}
// [ COMPRESSION compression_method ]
if p.eat(COMPRESSION_KW) && (p.at(DEFAULT_KW) || p.at(IDENT)) {
p.bump_any();
}
opt_collate(p);
}
}
ColDefType::ColumnNameOnly => {
Expand All @@ -3817,6 +3818,7 @@ fn col_def(p: &mut Parser<'_>, t: ColDefType) -> Option<CompletedMarker> {
}
}
}
opt_collate(p);
// [ column_constraint [ ... ] ]
while !p.at(EOF) {
if opt_column_constraint(p).is_none() {
Expand Down Expand Up @@ -4861,10 +4863,9 @@ fn stmt(p: &mut Parser, r: &StmtRestrictions) -> Option<CompletedMarker> {
CONSTRAINT_KW | TRIGGER_KW => Some(create_trigger(p)),
PROCEDURAL_KW | TRUSTED_KW | LANGUAGE_KW => Some(create_language(p)),
PROCEDURE_KW => Some(create_procedure(p)),
RECURSIVE_KW | TEMP_KW | TEMPORARY_KW => Some(create_view(p)),
RECURSIVE_KW | TEMP_KW | TEMPORARY_KW | VIEW_KW => Some(create_view(p)),
RULE_KW => Some(create_rule(p)),
TRANSFORM_KW => Some(create_transform(p)),
VIEW_KW => Some(create_view(p)),
_ => Some(create_function(p)),
}
}
Expand Down Expand Up @@ -10901,7 +10902,7 @@ fn reset(p: &mut Parser<'_>) -> CompletedMarker {
let m = p.start();
p.bump(RESET_KW);
if !p.eat(ALL_KW) {
name_ref(p);
path_name_ref(p);
}
m.complete(p, RESET)
}
Expand Down Expand Up @@ -11367,6 +11368,7 @@ fn copy(p: &mut Parser<'_>) -> CompletedMarker {
preparable_stmt(p);
p.expect(R_PAREN);
} else {
p.eat(BINARY_KW);
// table_name
path_name(p);
// [ ( column_name [, ...] ) ]
Expand Down Expand Up @@ -11593,19 +11595,41 @@ fn opt_schema_auth(p: &mut Parser<'_>) -> bool {
fn opt_schema_elements(p: &mut Parser<'_>) {
while !p.at(EOF) {
match (p.current(), p.nth(1)) {
(CREATE_KW, TABLE_KW) => {
(CREATE_KW, TABLE_KW | GLOBAL_KW | LOCAL_KW | UNLOGGED_KW)
if !p.nth_at(2, SEQUENCE_KW) =>
{
create_table(p);
}
(CREATE_KW, VIEW_KW) => {
(CREATE_KW, TEMP_KW | TEMPORARY_KW) => {
// CREATE TEMP [ RECURSIVE ] VIEW
// CREATE TEMP TABLE
// ^0 ^1 ^2
match p.nth(2) {
RECURSIVE_KW | VIEW_KW => create_view(p),
SEQUENCE_KW => create_sequence(p),
_ => create_table(p),
};
}
(CREATE_KW, OR_KW) => {
match p.nth(3) {
CONSTRAINT_KW | TRIGGER_KW => create_trigger(p),
RECURSIVE_KW | TEMP_KW | TEMPORARY_KW | VIEW_KW => create_view(p),
_ => return,
};
}
(CREATE_KW, RECURSIVE_KW | VIEW_KW) => {
create_view(p);
}
(CREATE_KW, UNLOGGED_KW) if p.nth_at(2, SEQUENCE_KW) => {
create_sequence(p);
}
(CREATE_KW, SEQUENCE_KW) => {
create_sequence(p);
}
(CREATE_KW, TRIGGER_KW) => {
(CREATE_KW, CONSTRAINT_KW | TRIGGER_KW) => {
create_trigger(p);
}
(CREATE_KW, INDEX_KW) => {
(CREATE_KW, INDEX_KW | UNIQUE_KW) => {
create_index(p);
}
_ => return,
Expand Down Expand Up @@ -11953,10 +11977,8 @@ fn opt_returning_clause(p: &mut Parser<'_>) {
if !p.eat(STAR) {
if expr(p).is_none() {
p.error("expected output expression");
} else if p.eat(AS_KW) {
p.expect(IDENT);
} else {
p.eat(IDENT);
opt_alias(p);
}
}
if !p.eat(COMMA) {
Expand Down Expand Up @@ -12778,7 +12800,7 @@ fn set(p: &mut Parser<'_>) -> CompletedMarker {
// configuration_parameter { TO | = } { value | 'value' | DEFAULT }
} else {
// configuration_parameter
name_ref(p);
path_name_ref(p);
// { TO | = }
let _ = p.eat(TO_KW) || p.expect(EQ);
// { value | 'value' | DEFAULT }
Expand All @@ -12798,7 +12820,7 @@ fn show(p: &mut Parser<'_>) -> CompletedMarker {
let m = p.start();
p.bump(SHOW_KW);
if !p.eat(ALL_KW) {
name_ref(p);
path_name_ref(p);
}
m.complete(p, SHOW)
}
Expand Down
14 changes: 7 additions & 7 deletions crates/squawk_parser/tests/data/regression_suite/copyselect.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ copy (select * from test1) from stdin;
--
-- This should fail
--
copy (select * from test1) (t,id) to stdout;
-- copy (select * from test1) (t,id) to stdout;
--
-- Test JOIN
--
Expand Down Expand Up @@ -79,13 +79,13 @@ drop view v_test1;
drop table test1;

-- psql handling of COPY in multi-command strings
copy (select 1) to stdout\; select 1/0; -- row, then error
select 1/0\; copy (select 1) to stdout; -- error only
copy (select 1) to stdout\; copy (select 2) to stdout\; select 3\; select 4; -- 1 2 3 4
-- copy (select 1) to stdout\; select 1/0; -- row, then error
-- select 1/0\; copy (select 1) to stdout; -- error only
-- copy (select 1) to stdout\; copy (select 2) to stdout\; select 3\; select 4; -- 1 2 3 4

create table test3 (c int);
select 0\; copy test3 from stdin\; copy test3 from stdin\; select 1; -- 0 1
1
2
-- select 0\; copy test3 from stdin\; copy test3 from stdin\; select 1; -- 0 1
-- 1
-- 2
select * from test3;
drop table test3;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CREATE INDEX onek_unique1 ON onek USING btree(unique1 int4_ops);

CREATE INDEX IF NOT EXISTS onek_unique1 ON onek USING btree(unique1 int4_ops);

CREATE INDEX IF NOT EXISTS ON onek USING btree(unique1 int4_ops);
-- CREATE INDEX IF NOT EXISTS ON onek USING btree(unique1 int4_ops);

CREATE INDEX onek_unique2 ON onek USING btree(unique2 int4_ops);

Expand Down Expand Up @@ -1382,7 +1382,7 @@ SELECT oid, relname, relfilenode, relkind, reltoastrelid
FROM pg_class
WHERE relname IN ('concur_temp_ind_1', 'concur_temp_ind_2');
SELECT pg_my_temp_schema()::regnamespace as temp_schema_name ;
REINDEX SCHEMA CONCURRENTLY 'temp_schema_name';
REINDEX SCHEMA CONCURRENTLY "temp_schema_name";
SELECT b.relname,
b.relkind,
CASE WHEN a.relfilenode = b.relfilenode THEN 'relfilenode is unchanged'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CREATE OPERATOR !=- (
);
SELECT !=- 10;
-- postfix operators don't work anymore
SELECT 10 !=-;
-- SELECT 10 !=-;
-- make sure lexer returns != as <> even in edge cases
SELECT 2 !=/**/ 1, 2 !=/**/ 2;
SELECT 2 !=-- comment to be removed by psql
Expand Down Expand Up @@ -86,21 +86,21 @@ ROLLBACK;


-- Should fail. SETOF type functions not allowed as argument (testing leftarg)
BEGIN TRANSACTION;
CREATE OPERATOR #*# (
leftarg = SETOF int8,
procedure = factorial
);
ROLLBACK;
-- BEGIN TRANSACTION;
-- CREATE OPERATOR #*# (
-- leftarg = SETOF int8,
-- procedure = factorial
-- );
-- ROLLBACK;


-- Should fail. SETOF type functions not allowed as argument (testing rightarg)
BEGIN TRANSACTION;
CREATE OPERATOR #*# (
rightarg = SETOF int8,
procedure = factorial
);
ROLLBACK;
-- BEGIN TRANSACTION;
-- CREATE OPERATOR #*# (
-- rightarg = SETOF int8,
-- procedure = factorial
-- );
-- ROLLBACK;


-- Should work. Sample text-book case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ DEALLOCATE select1;
-- create an extra wide table to test for issues related to that
-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
SELECT 'CREATE TABLE extra_wide_table(firstc text, '|| array_to_string(array_agg('c'||i||' bool'),',')||', lastc text);'
FROM generate_series(1, 1100) g(i)
FROM generate_series(1, 1100) g(i);
INSERT INTO extra_wide_table(firstc, lastc) VALUES('first col', 'last col');
SELECT firstc, lastc FROM extra_wide_table;

-- check that tables with oids cannot be created anymore
CREATE TABLE withoid() WITH OIDS;
-- CREATE TABLE withoid() WITH OIDS;
CREATE TABLE withoid() WITH (oids);
CREATE TABLE withoid() WITH (oids = true);

Expand Down Expand Up @@ -302,7 +302,7 @@ CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (genera
CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN ((1+1) collate "POSIX");

-- syntax does not allow empty list of values for list partitions
CREATE TABLE fail_part PARTITION OF list_parted FOR VALUES IN ();
-- CREATE TABLE fail_part PARTITION OF list_parted FOR VALUES IN ();
-- trying to specify range for list partitioned table
CREATE TABLE fail_part PARTITION OF list_parted FOR VALUES FROM (1) TO (2);
-- trying to specify modulus and remainder for list partitioned table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ ALTER TABLE ctl_table ALTER COLUMN b SET STORAGE MAIN;


-- Test EXCLUDING ALL
CREATE FOREIGN TABLE ctl_foreign_table1(LIKE ctl_table EXCLUDING ALL) SERVER ctl_s0;
-- CREATE FOREIGN TABLE ctl_foreign_table1(LIKE ctl_table EXCLUDING ALL) SERVER ctl_s0;
-- \d+ does not report the value of attcompression for a foreign table, so
-- check separately.
SELECT attname, attcompression FROM pg_attribute
WHERE attrelid = 'ctl_foreign_table1'::regclass and attnum > 0 ORDER BY attnum;

-- Test INCLUDING ALL
-- INDEXES, IDENTITY, COMPRESSION, STORAGE are not copied.
CREATE FOREIGN TABLE ctl_foreign_table2(LIKE ctl_table INCLUDING ALL) SERVER ctl_s0;
-- CREATE FOREIGN TABLE ctl_foreign_table2(LIKE ctl_table INCLUDING ALL) SERVER ctl_s0;
-- \d+ does not report the value of attcompression for a foreign table, so
-- check separately.
SELECT attname, attcompression FROM pg_attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ create domain d_fail as anyelement;
create domain d_fail as int4 unique;
create domain d_fail as int4 PRIMARY key;
create domain d_fail as int4 constraint cc generated by default as identity;
create domain d_fail as int4 constraint cc check (values > 1) no inherit;
-- create domain d_fail as int4 constraint cc check (values > 1) no inherit;
create domain d_fail as int4 constraint cc check (values > 1) deferrable;

-- Test domain input.
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_parser/tests/data/regression_suite/insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,9 @@ create trigger donothingbrtrig2 before insert on donothingbrtrig_test2 for each
alter table donothingbrtrig_test attach partition donothingbrtrig_test1 for values in (1);
alter table donothingbrtrig_test attach partition donothingbrtrig_test2 for values in (2);
insert into donothingbrtrig_test values (1, 'foo'), (2, 'bar');
copy donothingbrtrig_test from stdout;
1 baz
2 qux
-- copy donothingbrtrig_test from stdout;
-- 1 baz
-- 2 qux
select tableoid::regclass, * from donothingbrtrig_test;

-- cleanup
Expand Down
10 changes: 5 additions & 5 deletions crates/squawk_parser/tests/data/regression_suite/largeobject.sql
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ END;
-- Note: we intentionally don't remove the object created here;
-- it's left behind to help test pg_dump.

SELECT lo_from_bytea(0, lo_get(loid)) AS newloid FROM lotest_stash_values
SELECT lo_from_bytea(0, lo_get(loid)) AS newloid FROM lotest_stash_values;

-- Add a comment to it, as well, for pg_dump/pg_upgrade testing.
COMMENT ON LARGE OBJECT 'newloid' IS 'I Wandered Lonely as a Cloud';
COMMENT ON LARGE OBJECT 1235 IS 'I Wandered Lonely as a Cloud';

-- Read out a portion
BEGIN;
Expand Down Expand Up @@ -224,7 +224,7 @@ TRUNCATE lotest_stash_values;



SELECT lo_from_bytea(0, lo_get('newloid_1')) AS newloid_2
SELECT lo_from_bytea(0, lo_get('newloid_1')) AS newloid_2;

SELECT fipshash(lo_get('newloid_1')) = fipshash(lo_get('newloid_2'));

Expand All @@ -239,10 +239,10 @@ SELECT lo_get('newloid_1', 4294967294, 100);


-- This object is left in the database for pg_dump test purposes
SELECT lo_from_bytea(0, E'\\xdeadbeef') AS newloid
SELECT lo_from_bytea(0, E'\\xdeadbeef') AS newloid;

SET bytea_output TO hex;
SELECT lo_get('newloid');
SELECT lo_get(1235);

-- Create one more object that we leave behind for testing pg_dump/pg_upgrade;
-- this one intentionally has an OID in the system range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ DROP ROLE regress_log_memory;
-- directly, but we can at least verify that the code doesn't fail.
--
select setting as segsize
from pg_settings where name = 'wal_segment_size'
from pg_settings where name = 'wal_segment_size';

select count(*) > 0 as ok from pg_ls_waldir();
-- Test ProjectSet as well as FunctionScan
Expand Down Expand Up @@ -360,7 +360,7 @@ SELECT segment_number > 0 AS ok_segment_number, timeline_id
FROM pg_split_walfile_name('ffffffFF00000001000000af');
SELECT setting::int8 AS segment_size
FROM pg_settings
WHERE name = 'wal_segment_size'
WHERE name = 'wal_segment_size';
SELECT segment_number, file_offset
FROM pg_walfile_name_offset('0/0'::pg_lsn + 'segment_size'),
pg_split_walfile_name(file_name);
Expand All @@ -387,9 +387,9 @@ CREATE TABLE test_chunk_id (a TEXT, b TEXT STORAGE EXTERNAL);
INSERT INTO test_chunk_id VALUES ('x', repeat('x', 8192));
SELECT t.relname AS toastrel FROM pg_class c
LEFT JOIN pg_class t ON c.reltoastrelid = t.oid
WHERE c.relname = 'test_chunk_id'
WHERE c.relname = 'test_chunk_id';
SELECT pg_column_toast_chunk_id(a) IS NULL,
pg_column_toast_chunk_id(b) IN (SELECT chunk_id FROM pg_toast.'toastrel')
pg_column_toast_chunk_id(b) IN (SELECT chunk_id FROM pg_toast."toastrel")
FROM test_chunk_id;
DROP TABLE test_chunk_id;
DROP FUNCTION explain_mask_costs(text, bool, bool, bool, bool);
Expand Down
10 changes: 5 additions & 5 deletions crates/squawk_parser/tests/data/regression_suite/namespace.sql
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ SELECT COUNT(*) FROM pg_class WHERE relnamespace =
-- test IF NOT EXISTS cases
CREATE SCHEMA test_ns_schema_renamed; -- fail, already exists
CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed; -- ok with notice
CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed -- fail, disallowed
CREATE TABLE abc (
a serial,
b int UNIQUE
);
-- CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed -- fail, disallowed
-- CREATE TABLE abc (
-- a serial,
-- b int UNIQUE
-- );

DROP SCHEMA test_ns_schema_renamed CASCADE;

Expand Down
Loading
Loading