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
1 change: 1 addition & 0 deletions crates/squawk_parser/src/generated/syntax_kind.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12420,6 +12420,10 @@ fn conflict_action(p: &mut Parser<'_>) {
p.expect(DO_KW);
if p.eat(NOTHING_KW) {
m.complete(p, CONFLICT_DO_NOTHING);
} else if p.eat(SELECT_KW) {
opt_locking_clause(p);
opt_where_clause(p);
m.complete(p, CONFLICT_DO_SELECT);
} else {
p.expect(UPDATE_KW);
set_clause(p);
Expand Down
3 changes: 3 additions & 0 deletions crates/squawk_parser/tests/data/ok/insert_pg18.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- on conflict do select
INSERT INTO t (a) VALUES (1)
ON CONFLICT (a) DO SELECT FOR UPDATE WHERE a > 0 RETURNING *;
77 changes: 77 additions & 0 deletions crates/squawk_parser/tests/snapshots/tests__insert_pg18_ok.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
source: crates/squawk_parser/tests/tests.rs
input_file: crates/squawk_parser/tests/data/ok/insert_pg18.sql
---
SOURCE_FILE
COMMENT "-- on conflict do select"
WHITESPACE "\n"
INSERT
INSERT_KW "INSERT"
WHITESPACE " "
INTO_KW "INTO"
WHITESPACE " "
PATH
PATH_SEGMENT
NAME_REF
IDENT "t"
WHITESPACE " "
COLUMN_LIST
L_PAREN "("
COLUMN
NAME_REF
IDENT "a"
R_PAREN ")"
WHITESPACE " "
VALUES
VALUES_KW "VALUES"
WHITESPACE " "
ROW_LIST
ROW
L_PAREN "("
LITERAL
INT_NUMBER "1"
R_PAREN ")"
WHITESPACE "\n "
ON_CONFLICT_CLAUSE
ON_KW "ON"
WHITESPACE " "
CONFLICT_KW "CONFLICT"
WHITESPACE " "
CONFLICT_ON_INDEX
CONFLICT_INDEX_ITEM_LIST
L_PAREN "("
CONFLICT_INDEX_ITEM
NAME_REF
IDENT "a"
R_PAREN ")"
WHITESPACE " "
CONFLICT_DO_SELECT
DO_KW "DO"
WHITESPACE " "
SELECT_KW "SELECT"
WHITESPACE " "
LOCKING_CLAUSE
FOR_KW "FOR"
WHITESPACE " "
UPDATE_KW "UPDATE"
WHITESPACE " "
WHERE_CLAUSE
WHERE_KW "WHERE"
WHITESPACE " "
BIN_EXPR
NAME_REF
IDENT "a"
WHITESPACE " "
R_ANGLE ">"
WHITESPACE " "
LITERAL
INT_NUMBER "0"
WHITESPACE " "
RETURNING_CLAUSE
RETURNING_KW "RETURNING"
WHITESPACE " "
TARGET_LIST
TARGET
STAR "*"
SEMICOLON ";"
WHITESPACE "\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/squawk_parser/tests/tests.rs
input_file: postgres/regression_suite/encoding.sql
---

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/squawk_parser/tests/tests.rs
input_file: postgres/regression_suite/euc_kr.sql
---

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/squawk_parser/tests/tests.rs
input_file: postgres/regression_suite/oid8.sql
---

56 changes: 55 additions & 1 deletion crates/squawk_syntax/src/ast/generated/nodes.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/squawk_syntax/src/postgresql.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -1305,13 +1305,17 @@ ConflictIndexItem =
ConflictAction =
ConflictDoNothing
| ConflictDoUpdateSet
| ConflictDoSelect

ConflictDoUpdateSet =
'do' 'update' SetClause WhereClause?

ConflictDoNothing =
'do' 'nothing'

ConflictDoSelect =
'do' 'select' LockingClause? WhereClause?

SetClause =
'set' SetColumnList

Expand Down
8 changes: 5 additions & 3 deletions crates/xtask/src/sync_regression_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ pub(crate) fn preprocess_sql<R: BufRead, W: Write>(source: R, mut dest: W) -> Re
in_copy_stdin = false;
}
should_comment = true;
} else if (line.trim_start().starts_with('\\') && !line.contains("\\gset"))
} else if (line.trim_start().starts_with('\\')
&& !line.contains("\\gset")
&& !line.contains("\\gx"))
|| line.starts_with("'show_data'")
|| line.starts_with(':')
{
Expand Down Expand Up @@ -318,8 +320,8 @@ pub(crate) fn preprocess_sql<R: BufRead, W: Write>(source: R, mut dest: W) -> Re
line = line.replace(from, to);
}

if line.contains("\\gset") {
if let Some(start) = line.find("\\gset") {
for pattern in ["\\gx", "\\gset"] {
if let Some(start) = line.find(pattern) {
let end = line[start..]
.find('\n')
.map(|i| start + i)
Expand Down
8 changes: 4 additions & 4 deletions postgres/kwlist.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// synced from:
// commit: e5f3839af685c303d8ebcc1ea0d407c124372931
// committed at: 2025-12-22T22:41:34Z
// file: https://github.com/postgres/postgres/blob/e5f3839af685c303d8ebcc1ea0d407c124372931/src/include/parser/kwlist.h
// commit: ef3c3cf6d021ff9884c513afd850a9fe85cad736
// committed at: 2026-02-14T06:50:06Z
// file: https://github.com/postgres/postgres/blob/ef3c3cf6d021ff9884c513afd850a9fe85cad736/src/include/parser/kwlist.h
//
// update via:
// cargo xtask sync-kwlist
Expand All @@ -15,7 +15,7 @@
* by the PG_KEYWORD macro, which is not defined in this file; it can
* be defined by the caller for special purposes.
*
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
Expand Down
11 changes: 9 additions & 2 deletions postgres/regression_suite/arrays.sql
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ select '[2147483646:2147483646]={1}'::int[];
select '[-2147483648:-2147483647]={1,2}'::int[];
-- all of the above should be accepted

-- some day we might allow these cases, but for now they're errors:
select array[]::oidvector;
select array[]::int2vector;

-- tests for array aggregates
CREATE TEMP TABLE arraggtest ( f1 INT[], f2 TEXT[][], f3 FLOAT[]);

Expand Down Expand Up @@ -555,19 +559,22 @@ SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;

-- A few simple tests for arrays of composite types

create type comptype as (f1 int, f2 text);
create type comptype as (f1 int, f2 text, f3 int[]);

create table comptable (c1 comptype, c2 comptype[]);

-- XXX would like to not have to specify row() construct types here ...
insert into comptable
values (row(1,'foo'), array[row(2,'bar')::comptype, row(3,'baz')::comptype]);
values (row(1,'foo',array[10,20]), array[row(2,'bar',array[30,40])::comptype, row(3,'baz',array[50,60])::comptype]);

-- check that implicitly named array type _comptype isn't a problem
create type _comptype as enum('fooey');

select * from comptable;
select c2[2].f2 from comptable;
select c2[2].f3 from comptable;
select c2[2].f3[1:2] from comptable;
select c2[1:2].f3[1:2] from comptable;

drop type _comptype;
drop table comptable;
Expand Down
7 changes: 6 additions & 1 deletion postgres/regression_suite/constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ INSERT INTO circles VALUES('<(20,20), 10>', '<(0,0), 4>')
-- fail, because DO UPDATE variant requires unique index
INSERT INTO circles VALUES('<(20,20), 10>', '<(0,0), 4>')
ON CONFLICT ON CONSTRAINT circles_c1_c2_excl DO UPDATE SET c2 = EXCLUDED.c2;
-- fail, because DO SELECT variant requires unique index
INSERT INTO circles VALUES('<(20,20), 10>', '<(0,0), 4>')
ON CONFLICT ON CONSTRAINT circles_c1_c2_excl DO SELECT RETURNING *;
-- succeed because c1 doesn't overlap
INSERT INTO circles VALUES('<(20,20), 1>', '<(0,0), 5>');
-- succeed because c2 doesn't overlap
Expand Down Expand Up @@ -623,7 +626,9 @@ DROP TABLE deferred_excl;
-- verify constraints created for NOT NULL clauses
CREATE TABLE notnull_tbl1 (a INTEGER NOT NULL NOT NULL);
-- \d+ notnull_tbl1
-- no-op
-- specifying an existing constraint is a no-op
ALTER TABLE notnull_tbl1 ADD CONSTRAINT notnull_tbl1_a_not_null NOT NULL a;
-- but using a different constraint name is not allowed
ALTER TABLE notnull_tbl1 ADD CONSTRAINT nn NOT NULL a;
-- \d+ notnull_tbl1
-- duplicate name
Expand Down
15 changes: 15 additions & 0 deletions postgres/regression_suite/copy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ copy copytest5 from stdin (format csv, header 5);
-- \.
select count(*) from copytest5;

-- test header line feature (given as strings)
truncate copytest5;
copy copytest5 from stdin (format csv, header '0');
-- 1
-- 2
-- \.
select * from copytest5 order by c1;

truncate copytest5;
copy copytest5 from stdin (format csv, header '1');
-- 1
-- 2
-- \.
select * from copytest5 order by c1;

-- test copy from with a partitioned table
create table parted_copytest (
a int,
Expand Down
3 changes: 3 additions & 0 deletions postgres/regression_suite/copy2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ COPY x from stdin with (on_error ignore, reject_limit 0);
COPY x from stdin with (header -1);
COPY x from stdin with (header 2.5);
-- COPY x to stdout with (header 2);
COPY x to stdout with (header '-1');
COPY x from stdin with (header '2.5');
-- COPY x to stdout with (header '2');

-- too many columns in column list: should fail
COPY x (a, b, c, d, e, d, c) from stdin;
Expand Down
7 changes: 7 additions & 0 deletions postgres/regression_suite/copyencoding.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ CREATE TABLE copy_encoding_tab (t text);
COPY (SELECT E'\u3042') TO 'utf8_csv' WITH (FORMAT csv, ENCODING 'UTF8');
-- Read UTF8 data as LATIN1: no error
COPY copy_encoding_tab FROM 'utf8_csv' WITH (FORMAT csv, ENCODING 'LATIN1');
-- Non-server encodings have distinct code paths.
-- \set fname :abs_builddir '/results/copyencoding_gb18030.csv'
COPY (SELECT E'\u3042,') TO 'fname' WITH (FORMAT csv, ENCODING 'GB18030');
COPY copy_encoding_tab FROM 'fname' WITH (FORMAT csv, ENCODING 'GB18030');
-- \set fname :abs_builddir '/results/copyencoding_gb18030.data'
COPY (SELECT E'\u3042,') TO 'fname' WITH (FORMAT text, ENCODING 'GB18030');
COPY copy_encoding_tab FROM 'fname' WITH (FORMAT text, ENCODING 'GB18030');

-- Use client_encoding
SET client_encoding TO UTF8;
Expand Down
Loading
Loading