Skip to content

Commit 254be96

Browse files
authored
parser: fix more pg test suite errors part 5 (#524)
1 parent 0a90913 commit 254be96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+179
-812
lines changed

crates/squawk_parser/src/grammar.rs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,6 @@ fn atom_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
782782
p.bump(POSITIONAL_PARAM);
783783
m.complete(p, LITERAL)
784784
}
785-
(VALUES_KW, _) => values(p, None),
786785
(EXTRACT_KW, L_PAREN) => extract_fn(p),
787786
(JSON_EXISTS_KW, L_PAREN) => json_exists_fn(p),
788787
(JSON_ARRAY_KW, L_PAREN) => json_array_fn(p),
@@ -3034,7 +3033,10 @@ enum ColumnDefKind {
30343033
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30353034
// [ ( column_name [, ... ] ) ]
30363035
fn opt_column_list_with(p: &mut Parser<'_>, kind: ColumnDefKind) -> bool {
3037-
if !p.at(L_PAREN) {
3036+
if !p.at(L_PAREN) ||
3037+
// we're probably at (select)
3038+
!p.nth_at_ts(1, COLUMN_FIRST)
3039+
{
30383040
return false;
30393041
}
30403042
let m = p.start();
@@ -3800,14 +3802,13 @@ fn col_def(p: &mut Parser<'_>, t: ColDefType) -> Option<CompletedMarker> {
38003802
// TODO: validation to check for missing types
38013803
if opt_type_name(p) {
38023804
// [ STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } ]
3803-
if p.eat(STORAGE_KW) && (p.at(DEFAULT_KW) || p.at(IDENT)) {
3805+
if p.eat(STORAGE_KW) && (p.at(DEFAULT_KW) || p.at(EXTERNAL_KW) || p.at(IDENT)) {
38043806
p.bump_any();
38053807
}
38063808
// [ COMPRESSION compression_method ]
38073809
if p.eat(COMPRESSION_KW) && (p.at(DEFAULT_KW) || p.at(IDENT)) {
38083810
p.bump_any();
38093811
}
3810-
opt_collate(p);
38113812
}
38123813
}
38133814
ColDefType::ColumnNameOnly => {
@@ -3817,6 +3818,7 @@ fn col_def(p: &mut Parser<'_>, t: ColDefType) -> Option<CompletedMarker> {
38173818
}
38183819
}
38193820
}
3821+
opt_collate(p);
38203822
// [ column_constraint [ ... ] ]
38213823
while !p.at(EOF) {
38223824
if opt_column_constraint(p).is_none() {
@@ -4861,10 +4863,9 @@ fn stmt(p: &mut Parser, r: &StmtRestrictions) -> Option<CompletedMarker> {
48614863
CONSTRAINT_KW | TRIGGER_KW => Some(create_trigger(p)),
48624864
PROCEDURAL_KW | TRUSTED_KW | LANGUAGE_KW => Some(create_language(p)),
48634865
PROCEDURE_KW => Some(create_procedure(p)),
4864-
RECURSIVE_KW | TEMP_KW | TEMPORARY_KW => Some(create_view(p)),
4866+
RECURSIVE_KW | TEMP_KW | TEMPORARY_KW | VIEW_KW => Some(create_view(p)),
48654867
RULE_KW => Some(create_rule(p)),
48664868
TRANSFORM_KW => Some(create_transform(p)),
4867-
VIEW_KW => Some(create_view(p)),
48684869
_ => Some(create_function(p)),
48694870
}
48704871
}
@@ -10901,7 +10902,7 @@ fn reset(p: &mut Parser<'_>) -> CompletedMarker {
1090110902
let m = p.start();
1090210903
p.bump(RESET_KW);
1090310904
if !p.eat(ALL_KW) {
10904-
name_ref(p);
10905+
path_name_ref(p);
1090510906
}
1090610907
m.complete(p, RESET)
1090710908
}
@@ -11367,6 +11368,7 @@ fn copy(p: &mut Parser<'_>) -> CompletedMarker {
1136711368
preparable_stmt(p);
1136811369
p.expect(R_PAREN);
1136911370
} else {
11371+
p.eat(BINARY_KW);
1137011372
// table_name
1137111373
path_name(p);
1137211374
// [ ( column_name [, ...] ) ]
@@ -11593,19 +11595,41 @@ fn opt_schema_auth(p: &mut Parser<'_>) -> bool {
1159311595
fn opt_schema_elements(p: &mut Parser<'_>) {
1159411596
while !p.at(EOF) {
1159511597
match (p.current(), p.nth(1)) {
11596-
(CREATE_KW, TABLE_KW) => {
11598+
(CREATE_KW, TABLE_KW | GLOBAL_KW | LOCAL_KW | UNLOGGED_KW)
11599+
if !p.nth_at(2, SEQUENCE_KW) =>
11600+
{
1159711601
create_table(p);
1159811602
}
11599-
(CREATE_KW, VIEW_KW) => {
11603+
(CREATE_KW, TEMP_KW | TEMPORARY_KW) => {
11604+
// CREATE TEMP [ RECURSIVE ] VIEW
11605+
// CREATE TEMP TABLE
11606+
// ^0 ^1 ^2
11607+
match p.nth(2) {
11608+
RECURSIVE_KW | VIEW_KW => create_view(p),
11609+
SEQUENCE_KW => create_sequence(p),
11610+
_ => create_table(p),
11611+
};
11612+
}
11613+
(CREATE_KW, OR_KW) => {
11614+
match p.nth(3) {
11615+
CONSTRAINT_KW | TRIGGER_KW => create_trigger(p),
11616+
RECURSIVE_KW | TEMP_KW | TEMPORARY_KW | VIEW_KW => create_view(p),
11617+
_ => return,
11618+
};
11619+
}
11620+
(CREATE_KW, RECURSIVE_KW | VIEW_KW) => {
1160011621
create_view(p);
1160111622
}
11623+
(CREATE_KW, UNLOGGED_KW) if p.nth_at(2, SEQUENCE_KW) => {
11624+
create_sequence(p);
11625+
}
1160211626
(CREATE_KW, SEQUENCE_KW) => {
1160311627
create_sequence(p);
1160411628
}
11605-
(CREATE_KW, TRIGGER_KW) => {
11629+
(CREATE_KW, CONSTRAINT_KW | TRIGGER_KW) => {
1160611630
create_trigger(p);
1160711631
}
11608-
(CREATE_KW, INDEX_KW) => {
11632+
(CREATE_KW, INDEX_KW | UNIQUE_KW) => {
1160911633
create_index(p);
1161011634
}
1161111635
_ => return,
@@ -11953,10 +11977,8 @@ fn opt_returning_clause(p: &mut Parser<'_>) {
1195311977
if !p.eat(STAR) {
1195411978
if expr(p).is_none() {
1195511979
p.error("expected output expression");
11956-
} else if p.eat(AS_KW) {
11957-
p.expect(IDENT);
1195811980
} else {
11959-
p.eat(IDENT);
11981+
opt_alias(p);
1196011982
}
1196111983
}
1196211984
if !p.eat(COMMA) {
@@ -12778,7 +12800,7 @@ fn set(p: &mut Parser<'_>) -> CompletedMarker {
1277812800
// configuration_parameter { TO | = } { value | 'value' | DEFAULT }
1277912801
} else {
1278012802
// configuration_parameter
12781-
name_ref(p);
12803+
path_name_ref(p);
1278212804
// { TO | = }
1278312805
let _ = p.eat(TO_KW) || p.expect(EQ);
1278412806
// { value | 'value' | DEFAULT }
@@ -12798,7 +12820,7 @@ fn show(p: &mut Parser<'_>) -> CompletedMarker {
1279812820
let m = p.start();
1279912821
p.bump(SHOW_KW);
1280012822
if !p.eat(ALL_KW) {
12801-
name_ref(p);
12823+
path_name_ref(p);
1280212824
}
1280312825
m.complete(p, SHOW)
1280412826
}

crates/squawk_parser/tests/data/regression_suite/copyselect.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ copy (select * from test1) from stdin;
4545
--
4646
-- This should fail
4747
--
48-
copy (select * from test1) (t,id) to stdout;
48+
-- copy (select * from test1) (t,id) to stdout;
4949
--
5050
-- Test JOIN
5151
--
@@ -79,13 +79,13 @@ drop view v_test1;
7979
drop table test1;
8080

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

8686
create table test3 (c int);
87-
select 0\; copy test3 from stdin\; copy test3 from stdin\; select 1; -- 0 1
88-
1
89-
2
87+
-- select 0\; copy test3 from stdin\; copy test3 from stdin\; select 1; -- 0 1
88+
-- 1
89+
-- 2
9090
select * from test3;
9191
drop table test3;

crates/squawk_parser/tests/data/regression_suite/create_index.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ CREATE INDEX onek_unique1 ON onek USING btree(unique1 int4_ops);
1212

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

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

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

@@ -1382,7 +1382,7 @@ SELECT oid, relname, relfilenode, relkind, reltoastrelid
13821382
FROM pg_class
13831383
WHERE relname IN ('concur_temp_ind_1', 'concur_temp_ind_2');
13841384
SELECT pg_my_temp_schema()::regnamespace as temp_schema_name ;
1385-
REINDEX SCHEMA CONCURRENTLY 'temp_schema_name';
1385+
REINDEX SCHEMA CONCURRENTLY "temp_schema_name";
13861386
SELECT b.relname,
13871387
b.relkind,
13881388
CASE WHEN a.relfilenode = b.relfilenode THEN 'relfilenode is unchanged'

crates/squawk_parser/tests/data/regression_suite/create_operator.sql

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ CREATE OPERATOR !=- (
4848
);
4949
SELECT !=- 10;
5050
-- postfix operators don't work anymore
51-
SELECT 10 !=-;
51+
-- SELECT 10 !=-;
5252
-- make sure lexer returns != as <> even in edge cases
5353
SELECT 2 !=/**/ 1, 2 !=/**/ 2;
5454
SELECT 2 !=-- comment to be removed by psql
@@ -86,21 +86,21 @@ ROLLBACK;
8686

8787

8888
-- Should fail. SETOF type functions not allowed as argument (testing leftarg)
89-
BEGIN TRANSACTION;
90-
CREATE OPERATOR #*# (
91-
leftarg = SETOF int8,
92-
procedure = factorial
93-
);
94-
ROLLBACK;
89+
-- BEGIN TRANSACTION;
90+
-- CREATE OPERATOR #*# (
91+
-- leftarg = SETOF int8,
92+
-- procedure = factorial
93+
-- );
94+
-- ROLLBACK;
9595

9696

9797
-- Should fail. SETOF type functions not allowed as argument (testing rightarg)
98-
BEGIN TRANSACTION;
99-
CREATE OPERATOR #*# (
100-
rightarg = SETOF int8,
101-
procedure = factorial
102-
);
103-
ROLLBACK;
98+
-- BEGIN TRANSACTION;
99+
-- CREATE OPERATOR #*# (
100+
-- rightarg = SETOF int8,
101+
-- procedure = factorial
102+
-- );
103+
-- ROLLBACK;
104104

105105

106106
-- Should work. Sample text-book case

crates/squawk_parser/tests/data/regression_suite/create_table.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ DEALLOCATE select1;
5252
-- create an extra wide table to test for issues related to that
5353
-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
5454
SELECT 'CREATE TABLE extra_wide_table(firstc text, '|| array_to_string(array_agg('c'||i||' bool'),',')||', lastc text);'
55-
FROM generate_series(1, 1100) g(i)
55+
FROM generate_series(1, 1100) g(i);
5656
INSERT INTO extra_wide_table(firstc, lastc) VALUES('first col', 'last col');
5757
SELECT firstc, lastc FROM extra_wide_table;
5858

5959
-- check that tables with oids cannot be created anymore
60-
CREATE TABLE withoid() WITH OIDS;
60+
-- CREATE TABLE withoid() WITH OIDS;
6161
CREATE TABLE withoid() WITH (oids);
6262
CREATE TABLE withoid() WITH (oids = true);
6363

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

304304
-- syntax does not allow empty list of values for list partitions
305-
CREATE TABLE fail_part PARTITION OF list_parted FOR VALUES IN ();
305+
-- CREATE TABLE fail_part PARTITION OF list_parted FOR VALUES IN ();
306306
-- trying to specify range for list partitioned table
307307
CREATE TABLE fail_part PARTITION OF list_parted FOR VALUES FROM (1) TO (2);
308308
-- trying to specify modulus and remainder for list partitioned table

crates/squawk_parser/tests/data/regression_suite/create_table_like.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ ALTER TABLE ctl_table ALTER COLUMN b SET STORAGE MAIN;
223223

224224

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

232232
-- Test INCLUDING ALL
233233
-- INDEXES, IDENTITY, COMPRESSION, STORAGE are not copied.
234-
CREATE FOREIGN TABLE ctl_foreign_table2(LIKE ctl_table INCLUDING ALL) SERVER ctl_s0;
234+
-- CREATE FOREIGN TABLE ctl_foreign_table2(LIKE ctl_table INCLUDING ALL) SERVER ctl_s0;
235235
-- \d+ does not report the value of attcompression for a foreign table, so
236236
-- check separately.
237237
SELECT attname, attcompression FROM pg_attribute

crates/squawk_parser/tests/data/regression_suite/domain.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ create domain d_fail as anyelement;
2828
create domain d_fail as int4 unique;
2929
create domain d_fail as int4 PRIMARY key;
3030
create domain d_fail as int4 constraint cc generated by default as identity;
31-
create domain d_fail as int4 constraint cc check (values > 1) no inherit;
31+
-- create domain d_fail as int4 constraint cc check (values > 1) no inherit;
3232
create domain d_fail as int4 constraint cc check (values > 1) deferrable;
3333

3434
-- Test domain input.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ create trigger donothingbrtrig2 before insert on donothingbrtrig_test2 for each
621621
alter table donothingbrtrig_test attach partition donothingbrtrig_test1 for values in (1);
622622
alter table donothingbrtrig_test attach partition donothingbrtrig_test2 for values in (2);
623623
insert into donothingbrtrig_test values (1, 'foo'), (2, 'bar');
624-
copy donothingbrtrig_test from stdout;
625-
1 baz
626-
2 qux
624+
-- copy donothingbrtrig_test from stdout;
625+
-- 1 baz
626+
-- 2 qux
627627
select tableoid::regclass, * from donothingbrtrig_test;
628628

629629
-- cleanup

crates/squawk_parser/tests/data/regression_suite/largeobject.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ END;
8585
-- Note: we intentionally don't remove the object created here;
8686
-- it's left behind to help test pg_dump.
8787

88-
SELECT lo_from_bytea(0, lo_get(loid)) AS newloid FROM lotest_stash_values
88+
SELECT lo_from_bytea(0, lo_get(loid)) AS newloid FROM lotest_stash_values;
8989

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

9393
-- Read out a portion
9494
BEGIN;
@@ -224,7 +224,7 @@ TRUNCATE lotest_stash_values;
224224

225225

226226

227-
SELECT lo_from_bytea(0, lo_get('newloid_1')) AS newloid_2
227+
SELECT lo_from_bytea(0, lo_get('newloid_1')) AS newloid_2;
228228

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

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

240240

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

244244
SET bytea_output TO hex;
245-
SELECT lo_get('newloid');
245+
SELECT lo_get(1235);
246246

247247
-- Create one more object that we leave behind for testing pg_dump/pg_upgrade;
248248
-- this one intentionally has an OID in the system range

crates/squawk_parser/tests/data/regression_suite/misc_functions.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ DROP ROLE regress_log_memory;
147147
-- directly, but we can at least verify that the code doesn't fail.
148148
--
149149
select setting as segsize
150-
from pg_settings where name = 'wal_segment_size'
150+
from pg_settings where name = 'wal_segment_size';
151151

152152
select count(*) > 0 as ok from pg_ls_waldir();
153153
-- Test ProjectSet as well as FunctionScan
@@ -360,7 +360,7 @@ SELECT segment_number > 0 AS ok_segment_number, timeline_id
360360
FROM pg_split_walfile_name('ffffffFF00000001000000af');
361361
SELECT setting::int8 AS segment_size
362362
FROM pg_settings
363-
WHERE name = 'wal_segment_size'
363+
WHERE name = 'wal_segment_size';
364364
SELECT segment_number, file_offset
365365
FROM pg_walfile_name_offset('0/0'::pg_lsn + 'segment_size'),
366366
pg_split_walfile_name(file_name);
@@ -387,9 +387,9 @@ CREATE TABLE test_chunk_id (a TEXT, b TEXT STORAGE EXTERNAL);
387387
INSERT INTO test_chunk_id VALUES ('x', repeat('x', 8192));
388388
SELECT t.relname AS toastrel FROM pg_class c
389389
LEFT JOIN pg_class t ON c.reltoastrelid = t.oid
390-
WHERE c.relname = 'test_chunk_id'
390+
WHERE c.relname = 'test_chunk_id';
391391
SELECT pg_column_toast_chunk_id(a) IS NULL,
392-
pg_column_toast_chunk_id(b) IN (SELECT chunk_id FROM pg_toast.'toastrel')
392+
pg_column_toast_chunk_id(b) IN (SELECT chunk_id FROM pg_toast."toastrel")
393393
FROM test_chunk_id;
394394
DROP TABLE test_chunk_id;
395395
DROP FUNCTION explain_mask_costs(text, bool, bool, bool, bool);

0 commit comments

Comments
 (0)