Skip to content

Commit 23ab4ae

Browse files
authored
Upgrade to Postgres 17 and libpg_query 6.0.0 (#47)
* Upgrade to libpg_query 17 * Update tests * Update crate and CHANGELOG
1 parent 4bbe866 commit 23ab4ae

11 files changed

+128
-15
lines changed

Diff for: CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Changelog
22

3+
## 6.0.0 2024-11-26
4+
5+
* Upgrade to libpg_query 17-6.0.0
6+
- Updates to the Postgres 17 parser
7+
- Deparser improvements:
8+
- Add support for deparsing `JSON_TABLE`, `JSON_QUERY`, `JSON_EXISTS`, `JSON_VALUE`
9+
- Add support for deparsing `JSON`, `JSON_SCALAR`, `JSON_SERIALIZE`
10+
- Add support for deparsing `COPY ... FORCE_NULL(*)`
11+
- Add support for deparsing `ALTER COLUMN ... SET EXPRESSION AS`
12+
- Add support for deparsing `SET STATISTICS DEFAULT`
13+
- Add support for deparsing `SET ACCESS METHOD DEFAULT`
14+
- Add support for deparsing `... AT LOCAL`
15+
- Add support for deparsing `merge_action()`
16+
- Add support for deparsing `MERGE ... RETURNING`
17+
- Add support for deparsing `NOT MATCHED [ BY TARGET ]`
18+
319
## 5.1.1 2024-10-30
420

521
* Make `ParseResult` struct public and implement `Debug`

Diff for: Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "pg_query"
33
description = "PostgreSQL parser that uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parse tree."
4-
version = "5.1.1"
4+
version = "6.0.0"
55
edition = "2021"
66
documentation = "https://docs.rs/pg_query/"
77
build = "build.rs"

Diff for: libpg_query

Submodule libpg_query updated 632 files

Diff for: src/node_enum.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,22 @@ impl NodeEnum {
11631163
NodeEnum::JsonObjectAgg(n) => NodeRef::JsonObjectAgg(n),
11641164
NodeEnum::JsonArrayAgg(n) => NodeRef::JsonArrayAgg(n),
11651165
NodeEnum::RtepermissionInfo(n) => NodeRef::RtepermissionInfo(n),
1166+
NodeEnum::WindowFuncRunCondition(n) => NodeRef::WindowFuncRunCondition(n),
1167+
NodeEnum::MergeSupportFunc(n) => NodeRef::MergeSupportFunc(n),
1168+
NodeEnum::JsonBehavior(n) => NodeRef::JsonBehavior(n),
1169+
NodeEnum::JsonExpr(n) => NodeRef::JsonExpr(n),
1170+
NodeEnum::JsonTablePath(n) => NodeRef::JsonTablePath(n),
1171+
NodeEnum::JsonTablePathScan(n) => NodeRef::JsonTablePathScan(n),
1172+
NodeEnum::JsonTableSiblingJoin(n) => NodeRef::JsonTableSiblingJoin(n),
1173+
NodeEnum::SinglePartitionSpec(n) => NodeRef::SinglePartitionSpec(n),
1174+
NodeEnum::JsonArgument(n) => NodeRef::JsonArgument(n),
1175+
NodeEnum::JsonFuncExpr(n) => NodeRef::JsonFuncExpr(n),
1176+
NodeEnum::JsonTablePathSpec(n) => NodeRef::JsonTablePathSpec(n),
1177+
NodeEnum::JsonTable(n) => NodeRef::JsonTable(n),
1178+
NodeEnum::JsonTableColumn(n) => NodeRef::JsonTableColumn(n),
1179+
NodeEnum::JsonParseExpr(n) => NodeRef::JsonParseExpr(n),
1180+
NodeEnum::JsonScalarExpr(n) => NodeRef::JsonScalarExpr(n),
1181+
NodeEnum::JsonSerializeExpr(n) => NodeRef::JsonSerializeExpr(n),
11661182
}
11671183
}
11681184

@@ -1332,7 +1348,7 @@ impl NodeEnum {
13321348
NodeEnum::CreateStatsStmt(n) => NodeMut::CreateStatsStmt(n as *mut _),
13331349
NodeEnum::AlterCollationStmt(n) => NodeMut::AlterCollationStmt(n as *mut _),
13341350
NodeEnum::CallStmt(n) => NodeMut::CallStmt(&mut **n as *mut _),
1335-
NodeEnum::AlterStatsStmt(n) => NodeMut::AlterStatsStmt(n as *mut _),
1351+
NodeEnum::AlterStatsStmt(n) => NodeMut::AlterStatsStmt(&mut **n as *mut _),
13361352
NodeEnum::AExpr(n) => NodeMut::AExpr(&mut **n as *mut _),
13371353
NodeEnum::ColumnRef(n) => NodeMut::ColumnRef(n as *mut _),
13381354
NodeEnum::ParamRef(n) => NodeMut::ParamRef(n as *mut _),
@@ -1420,6 +1436,22 @@ impl NodeEnum {
14201436
NodeEnum::JsonObjectAgg(n) => NodeMut::JsonObjectAgg(&mut **n as *mut _),
14211437
NodeEnum::JsonArrayAgg(n) => NodeMut::JsonArrayAgg(&mut **n as *mut _),
14221438
NodeEnum::RtepermissionInfo(n) => NodeMut::RtepermissionInfo(&mut *n as *mut _),
1439+
NodeEnum::WindowFuncRunCondition(n) => NodeMut::WindowFuncRunCondition(&mut **n as *mut _),
1440+
NodeEnum::MergeSupportFunc(n) => NodeMut::MergeSupportFunc(&mut **n as *mut _),
1441+
NodeEnum::JsonBehavior(n) => NodeMut::JsonBehavior(&mut **n as *mut _),
1442+
NodeEnum::JsonExpr(n) => NodeMut::JsonExpr(&mut **n as *mut _),
1443+
NodeEnum::JsonTablePath(n) => NodeMut::JsonTablePath(&mut *n as *mut _),
1444+
NodeEnum::JsonTablePathScan(n) => NodeMut::JsonTablePathScan(&mut **n as *mut _),
1445+
NodeEnum::JsonTableSiblingJoin(n) => NodeMut::JsonTableSiblingJoin(&mut **n as *mut _),
1446+
NodeEnum::SinglePartitionSpec(n) => NodeMut::SinglePartitionSpec(&mut *n as *mut _),
1447+
NodeEnum::JsonArgument(n) => NodeMut::JsonArgument(&mut **n as *mut _),
1448+
NodeEnum::JsonFuncExpr(n) => NodeMut::JsonFuncExpr(&mut **n as *mut _),
1449+
NodeEnum::JsonTablePathSpec(n) => NodeMut::JsonTablePathSpec(&mut **n as *mut _),
1450+
NodeEnum::JsonTable(n) => NodeMut::JsonTable(&mut **n as *mut _),
1451+
NodeEnum::JsonTableColumn(n) => NodeMut::JsonTableColumn(&mut **n as *mut _),
1452+
NodeEnum::JsonParseExpr(n) => NodeMut::JsonParseExpr(&mut **n as *mut _),
1453+
NodeEnum::JsonScalarExpr(n) => NodeMut::JsonScalarExpr(&mut **n as *mut _),
1454+
NodeEnum::JsonSerializeExpr(n) => NodeMut::JsonSerializeExpr(&mut **n as *mut _),
14231455
}
14241456
}
14251457
}

Diff for: src/node_mut.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,22 @@ pub enum NodeMut {
254254
JsonObjectAgg(*mut protobuf::JsonObjectAgg),
255255
JsonArrayAgg(*mut protobuf::JsonArrayAgg),
256256
RtepermissionInfo(*mut protobuf::RtePermissionInfo),
257+
WindowFuncRunCondition(*mut protobuf::WindowFuncRunCondition),
258+
MergeSupportFunc(*mut protobuf::MergeSupportFunc),
259+
JsonBehavior(*mut protobuf::JsonBehavior),
260+
JsonExpr(*mut protobuf::JsonExpr),
261+
JsonTablePath(*mut protobuf::JsonTablePath),
262+
JsonTablePathScan(*mut protobuf::JsonTablePathScan),
263+
JsonTableSiblingJoin(*mut protobuf::JsonTableSiblingJoin),
264+
SinglePartitionSpec(*mut protobuf::SinglePartitionSpec),
265+
JsonArgument(*mut protobuf::JsonArgument),
266+
JsonFuncExpr(*mut protobuf::JsonFuncExpr),
267+
JsonTablePathSpec(*mut protobuf::JsonTablePathSpec),
268+
JsonTable(*mut protobuf::JsonTable),
269+
JsonTableColumn(*mut protobuf::JsonTableColumn),
270+
JsonParseExpr(*mut protobuf::JsonParseExpr),
271+
JsonScalarExpr(*mut protobuf::JsonScalarExpr),
272+
JsonSerializeExpr(*mut protobuf::JsonSerializeExpr),
257273
}
258274

259275
impl NodeMut {
@@ -432,7 +448,7 @@ impl NodeMut {
432448
NodeMut::CreateStatsStmt(n) => Ok(NodeEnum::CreateStatsStmt(n.as_ref().ok_or(err)?.clone())),
433449
NodeMut::AlterCollationStmt(n) => Ok(NodeEnum::AlterCollationStmt(n.as_ref().ok_or(err)?.clone())),
434450
NodeMut::CallStmt(n) => Ok(NodeEnum::CallStmt(Box::new(n.as_ref().ok_or(err)?.clone()))),
435-
NodeMut::AlterStatsStmt(n) => Ok(NodeEnum::AlterStatsStmt(n.as_ref().ok_or(err)?.clone())),
451+
NodeMut::AlterStatsStmt(n) => Ok(NodeEnum::AlterStatsStmt(Box::new(n.as_ref().ok_or(err)?.clone()))),
436452
NodeMut::AExpr(n) => Ok(NodeEnum::AExpr(Box::new(n.as_ref().ok_or(err)?.clone()))),
437453
NodeMut::ColumnRef(n) => Ok(NodeEnum::ColumnRef(n.as_ref().ok_or(err)?.clone())),
438454
NodeMut::ParamRef(n) => Ok(NodeEnum::ParamRef(n.as_ref().ok_or(err)?.clone())),
@@ -520,6 +536,22 @@ impl NodeMut {
520536
NodeMut::JsonObjectAgg(n) => Ok(NodeEnum::JsonObjectAgg(Box::new(n.as_ref().ok_or(err)?.clone()))),
521537
NodeMut::JsonArrayAgg(n) => Ok(NodeEnum::JsonArrayAgg(Box::new(n.as_ref().ok_or(err)?.clone()))),
522538
NodeMut::RtepermissionInfo(n) => Ok(NodeEnum::RtepermissionInfo(n.as_ref().ok_or(err)?.clone())),
539+
NodeMut::WindowFuncRunCondition(n) => Ok(NodeEnum::WindowFuncRunCondition(Box::new(n.as_ref().ok_or(err)?.clone()))),
540+
NodeMut::MergeSupportFunc(n) => Ok(NodeEnum::MergeSupportFunc(Box::new(n.as_ref().ok_or(err)?.clone()))),
541+
NodeMut::JsonBehavior(n) => Ok(NodeEnum::JsonBehavior(Box::new(n.as_ref().ok_or(err)?.clone()))),
542+
NodeMut::JsonExpr(n) => Ok(NodeEnum::JsonExpr(Box::new(n.as_ref().ok_or(err)?.clone()))),
543+
NodeMut::JsonTablePath(n) => Ok(NodeEnum::JsonTablePath(n.as_ref().ok_or(err)?.clone())),
544+
NodeMut::JsonTablePathScan(n) => Ok(NodeEnum::JsonTablePathScan(Box::new(n.as_ref().ok_or(err)?.clone()))),
545+
NodeMut::JsonTableSiblingJoin(n) => Ok(NodeEnum::JsonTableSiblingJoin(Box::new(n.as_ref().ok_or(err)?.clone()))),
546+
NodeMut::SinglePartitionSpec(n) => Ok(NodeEnum::SinglePartitionSpec(n.as_ref().ok_or(err)?.clone())),
547+
NodeMut::JsonArgument(n) => Ok(NodeEnum::JsonArgument(Box::new(n.as_ref().ok_or(err)?.clone()))),
548+
NodeMut::JsonFuncExpr(n) => Ok(NodeEnum::JsonFuncExpr(Box::new(n.as_ref().ok_or(err)?.clone()))),
549+
NodeMut::JsonTablePathSpec(n) => Ok(NodeEnum::JsonTablePathSpec(Box::new(n.as_ref().ok_or(err)?.clone()))),
550+
NodeMut::JsonTable(n) => Ok(NodeEnum::JsonTable(Box::new(n.as_ref().ok_or(err)?.clone()))),
551+
NodeMut::JsonTableColumn(n) => Ok(NodeEnum::JsonTableColumn(Box::new(n.as_ref().ok_or(err)?.clone()))),
552+
NodeMut::JsonParseExpr(n) => Ok(NodeEnum::JsonParseExpr(Box::new(n.as_ref().ok_or(err)?.clone()))),
553+
NodeMut::JsonScalarExpr(n) => Ok(NodeEnum::JsonScalarExpr(Box::new(n.as_ref().ok_or(err)?.clone()))),
554+
NodeMut::JsonSerializeExpr(n) => Ok(NodeEnum::JsonSerializeExpr(Box::new(n.as_ref().ok_or(err)?.clone()))),
523555
}
524556
}
525557
}

Diff for: src/node_ref.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,22 @@ pub enum NodeRef<'a> {
254254
JsonObjectAgg(&'a protobuf::JsonObjectAgg),
255255
JsonArrayAgg(&'a protobuf::JsonArrayAgg),
256256
RtepermissionInfo(&'a protobuf::RtePermissionInfo),
257+
WindowFuncRunCondition(&'a protobuf::WindowFuncRunCondition),
258+
MergeSupportFunc(&'a protobuf::MergeSupportFunc),
259+
JsonBehavior(&'a protobuf::JsonBehavior),
260+
JsonExpr(&'a protobuf::JsonExpr),
261+
JsonTablePath(&'a protobuf::JsonTablePath),
262+
JsonTablePathScan(&'a protobuf::JsonTablePathScan),
263+
JsonTableSiblingJoin(&'a protobuf::JsonTableSiblingJoin),
264+
SinglePartitionSpec(&'a protobuf::SinglePartitionSpec),
265+
JsonArgument(&'a protobuf::JsonArgument),
266+
JsonFuncExpr(&'a protobuf::JsonFuncExpr),
267+
JsonTablePathSpec(&'a protobuf::JsonTablePathSpec),
268+
JsonTable(&'a protobuf::JsonTable),
269+
JsonTableColumn(&'a protobuf::JsonTableColumn),
270+
JsonParseExpr(&'a protobuf::JsonParseExpr),
271+
JsonScalarExpr(&'a protobuf::JsonScalarExpr),
272+
JsonSerializeExpr(&'a protobuf::JsonSerializeExpr),
257273
}
258274

259275
impl<'a> NodeRef<'a> {
@@ -431,7 +447,7 @@ impl<'a> NodeRef<'a> {
431447
NodeRef::CreateStatsStmt(n) => NodeEnum::CreateStatsStmt((*n).clone()),
432448
NodeRef::AlterCollationStmt(n) => NodeEnum::AlterCollationStmt((*n).clone()),
433449
NodeRef::CallStmt(n) => NodeEnum::CallStmt(Box::new((*n).clone())),
434-
NodeRef::AlterStatsStmt(n) => NodeEnum::AlterStatsStmt((*n).clone()),
450+
NodeRef::AlterStatsStmt(n) => NodeEnum::AlterStatsStmt(Box::new((*n).clone())),
435451
NodeRef::AExpr(n) => NodeEnum::AExpr(Box::new((*n).clone())),
436452
NodeRef::ColumnRef(n) => NodeEnum::ColumnRef((*n).clone()),
437453
NodeRef::ParamRef(n) => NodeEnum::ParamRef((*n).clone()),
@@ -519,6 +535,22 @@ impl<'a> NodeRef<'a> {
519535
NodeRef::JsonObjectAgg(n) => NodeEnum::JsonObjectAgg(Box::new((*n).clone())),
520536
NodeRef::JsonArrayAgg(n) => NodeEnum::JsonArrayAgg(Box::new((*n).clone())),
521537
NodeRef::RtepermissionInfo(n) => NodeEnum::RtepermissionInfo((*n).clone()),
538+
NodeRef::WindowFuncRunCondition(n) => NodeEnum::WindowFuncRunCondition(Box::new((*n).clone())),
539+
NodeRef::MergeSupportFunc(n) => NodeEnum::MergeSupportFunc(Box::new((*n).clone())),
540+
NodeRef::JsonBehavior(n) => NodeEnum::JsonBehavior(Box::new((*n).clone())),
541+
NodeRef::JsonExpr(n) => NodeEnum::JsonExpr(Box::new((*n).clone())),
542+
NodeRef::JsonTablePath(n) => NodeEnum::JsonTablePath((*n).clone()),
543+
NodeRef::JsonTablePathScan(n) => NodeEnum::JsonTablePathScan(Box::new((*n).clone())),
544+
NodeRef::JsonTableSiblingJoin(n) => NodeEnum::JsonTableSiblingJoin(Box::new((*n).clone())),
545+
NodeRef::SinglePartitionSpec(n) => NodeEnum::SinglePartitionSpec((*n).clone()),
546+
NodeRef::JsonArgument(n) => NodeEnum::JsonArgument(Box::new((*n).clone())),
547+
NodeRef::JsonFuncExpr(n) => NodeEnum::JsonFuncExpr(Box::new((*n).clone())),
548+
NodeRef::JsonTablePathSpec(n) => NodeEnum::JsonTablePathSpec(Box::new((*n).clone())),
549+
NodeRef::JsonTable(n) => NodeEnum::JsonTable(Box::new((*n).clone())),
550+
NodeRef::JsonTableColumn(n) => NodeEnum::JsonTableColumn(Box::new((*n).clone())),
551+
NodeRef::JsonParseExpr(n) => NodeEnum::JsonParseExpr(Box::new((*n).clone())),
552+
NodeRef::JsonScalarExpr(n) => NodeEnum::JsonScalarExpr(Box::new((*n).clone())),
553+
NodeRef::JsonSerializeExpr(n) => NodeEnum::JsonSerializeExpr(Box::new((*n).clone())),
522554
}
523555
}
524556
}

Diff for: tests/data/plpgsql_query.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"PLpgSQL_var": {
4949
"datatype": {
5050
"PLpgSQL_type": {
51-
"typname": "UNKNOWN"
51+
"typname": "pg_catalog.int4"
5252
}
5353
},
5454
"refname": "input"
@@ -58,7 +58,7 @@
5858
"PLpgSQL_var": {
5959
"datatype": {
6060
"PLpgSQL_type": {
61-
"typname": "UNKNOWN"
61+
"typname": "pg_catalog.\"boolean\""
6262
}
6363
},
6464
"refname": "found"

Diff for: tests/data/plpgsql_simple.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"PLpgSQL_var": {
4949
"datatype": {
5050
"PLpgSQL_type": {
51-
"typname": "UNKNOWN"
51+
"typname": "pg_catalog.\"varchar\""
5252
}
5353
},
5454
"refname": "v_name"
@@ -58,7 +58,7 @@
5858
"PLpgSQL_var": {
5959
"datatype": {
6060
"PLpgSQL_type": {
61-
"typname": "UNKNOWN"
61+
"typname": "pg_catalog.\"varchar\""
6262
}
6363
},
6464
"refname": "v_version"
@@ -68,7 +68,7 @@
6868
"PLpgSQL_var": {
6969
"datatype": {
7070
"PLpgSQL_type": {
71-
"typname": "UNKNOWN"
71+
"typname": "pg_catalog.\"boolean\""
7272
}
7373
},
7474
"refname": "found"

Diff for: tests/fingerprint_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn it_works() {
178178
assert_eq!(result.hex, "d8a65a814fbc5f95");
179179

180180
let result = fingerprint("DEALLOCATE ALL").unwrap();
181-
assert_eq!(result.hex, "d8a65a814fbc5f95");
181+
assert_eq!(result.hex, "2debfb8745df64a7");
182182

183183
let result = fingerprint("EXPLAIN ANALYZE SELECT a").unwrap();
184184
assert_eq!(result.hex, "82845c1b5c6102e5");

Diff for: tests/parse_tests.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ fn it_parses_ALTER_TABLE() {
125125
conname: "",
126126
deferrable: false,
127127
initdeferred: false,
128-
location: 21,
128+
skip_validation: false,
129+
initially_valid: false,
129130
is_no_inherit: false,
130131
raw_expr: None,
131132
cooked_expr: "",
132133
generated_when: "",
134+
inhcount: 0,
133135
nulls_not_distinct: false,
134136
keys: [
135137
Node {
@@ -159,8 +161,7 @@ fn it_parses_ALTER_TABLE() {
159161
fk_del_set_cols: [],
160162
old_conpfeqop: [],
161163
old_pktable_oid: 0,
162-
skip_validation: false,
163-
initially_valid: false,
164+
location: 21,
164165
},
165166
),
166167
),

0 commit comments

Comments
 (0)