Skip to content

Commit c7ccd3f

Browse files
committed
Merge commit '8d8d725a7f1d82b2686c3356cf60e96fd78b9c03'
2 parents dd739bf + 8d8d725 commit c7ccd3f

264 files changed

Lines changed: 13733 additions & 5331 deletions

File tree

Some content is hidden

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

c_src/libpg_query/.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.sql binary
1+
*.sql binary
2+
*.psql binary

c_src/libpg_query/.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
os: [ubuntu-20.04]
11+
os: [ubuntu-24.04]
1212
compiler: [clang, gcc]
1313
protobuf_lib: [protobuf-c, protobuf-cpp]
1414
valgrind: [valgrind,no-valgrind]
15+
exclude:
16+
# this combination hits linking errors: see https://github.com/pganalyze/libpg_query/pull/289
17+
- compiler: clang
18+
protobuf_lib: protobuf-cpp
19+
valgrind: valgrind
1520
steps:
1621
- name: Check out code
1722
uses: actions/checkout@v4
@@ -21,7 +26,7 @@ jobs:
2126
uses: actions/cache@v4
2227
with:
2328
path: protobuf-25.1
24-
key: ${{ runner.os }}-protobuf-25.1
29+
key: ${{ runner.os }}-${{ matrix.compiler }}-protobuf-25.1
2530
- name: Build protobuf library
2631
if: matrix.protobuf_lib == 'protobuf-cpp' && steps.cache-protobuf.outputs.cache-hit != 'true'
2732
run: |

c_src/libpg_query/CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,50 @@
22

33
All versions are tagged by the major Postgres version, plus an individual semver for this library itself.
44

5+
## 17-6.2.2 2026-01-26
6+
7+
* pg_query_normalize: Fix handling of special strings in DefElem [#325](https://github.com/pganalyze/libpg_query/pull/325)
8+
- This avoids a crash when running the normalize function on certain utility statements
9+
* pg_query_deparse_comments_for_query: Add missing initialization [#324](https://github.com/pganalyze/libpg_query/pull/324)
10+
- This avoids a crash for callers that read the error field of the result when there is no error
11+
12+
## 17-6.2.1 2026-01-14
13+
14+
* Add pg_query_is_utility_stmt function to determine if query text contains utility statements [#313](https://github.com/pganalyze/libpg_query/pull/313)
15+
* This is a fast check for callers that don't actually need the parse tree itself
16+
* Add missing top-level postgres_deparse.h in Makefile install step
17+
- This was an oversight from the previous 6.2.0 release
18+
* Improve pg_query_summary function:
19+
- Speed up summary truncate replacement logic
20+
- Correctly handle `GRANT .. ON ALL TABLES IN SCHEMA` statements
21+
- Correctly handle schema qualified filter columns
22+
23+
## 17-6.2.0 2025-12-10
24+
25+
* Add fast summary information function (pg_query_summary)
26+
- This allows gathering certain information, for example which tables are referenced in a
27+
statement, without requiring a Protobuf serialization step in a higher level library
28+
- Additionally this can also be used to perform "smart truncation" of a query by
29+
omitting deeply nested information (e.g. a CTE definition, or a target list) whilst
30+
preserving more essential parts like the FROM claus
31+
* Deparser:
32+
- Introduce pretty printing / formatting
33+
- Introduces a new optional pretty print mode that emits a human readable
34+
output. A detailed explanation of the mechanism can be found at the start
35+
of the deparser file.
36+
- Rework handling of expressions inside typecasts
37+
- Prefer (..)::type syntax, unless we are already in a function call.
38+
- Use lowercase keywords in xmlroot functions
39+
- This matches other XML functions as well as the Postgres documentation,
40+
since these are closer to function argument names than regular keywords.
41+
- Fix deparse of ALTER TABLE a ALTER b SET STATISTICS DEFAULT
42+
- Fix the null pointer dereference when handling identity columns
43+
* Allow alternate definitions of NAMEDATALEN identifier limit
44+
- This allows building libpg_query with an override of the built-time limit of
45+
Postgres identifiers (typically 63 characters)
46+
* Normalization: Add support for CALL statements
47+
* Bump Postgres to 17.7 and switch back to release tarballs
48+
549
## 17-6.1.0 2025-04-02
650

751
* Update to Postgres 17.4, and add recent patches scheduled for Postgres 17.5 (not yet released)

c_src/libpg_query/Makefile

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ PGDIR = $(root_dir)/tmp/postgres
77
PGDIRBZ2 = $(root_dir)/tmp/postgres.tar.bz2
88
PGDIRZIP = $(root_dir)/tmp/postgres.zip
99

10-
PG_VERSION = 17.4
10+
PG_VERSION = 17.7
1111
PG_VERSION_MAJOR = $(call word-dot,$(PG_VERSION),1)
12-
PG_VERSION_NUM = 170004
13-
PG_BRANCH = REL_17_STABLE
12+
PG_VERSION_NUM = 170007
1413
PROTOC_VERSION = 25.1
1514

16-
VERSION = 6.1.0
15+
VERSION = 6.2.2
1716
VERSION_MAJOR = $(call word-dot,$(VERSION),1)
1817
VERSION_MINOR = $(call word-dot,$(VERSION),2)
1918
VERSION_PATCH = $(call word-dot,$(VERSION),3)
@@ -39,6 +38,7 @@ override CFLAGS += -g -I. -I./vendor -I./src/include -I./src/postgres/include -W
3938

4039
ifeq ($(OS),Windows_NT)
4140
override CFLAGS += -I./src/postgres/include/port/win32
41+
override TEST_CFLAGS += -I./src/postgres/include/port/win32
4242
endif
4343

4444
override PG_CONFIGURE_FLAGS += -q --without-readline --without-zlib --without-icu
@@ -116,14 +116,9 @@ clean:
116116
.PHONY: all clean build build_shared extract_source examples test install
117117

118118
$(PGDIR):
119-
# We temporarily build off REL_17_STABLE to pull in https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=6da2ba1d8a031984eb016fed6741bb2ac945f19d
120-
# TODO: Go back to upstream tarball once 17.5 is released
121-
# tar -xjf $(PGDIRBZ2)
122-
# curl -o $(PGDIRBZ2) https://ftp.postgresql.org/pub/source/v$(PG_VERSION)/postgresql-$(PG_VERSION).tar.bz2
123-
# mv $(root_dir)/postgresql-$(PG_VERSION) $(PGDIR)
124-
curl -L -o $(PGDIRZIP) https://github.com/postgres/postgres/archive/refs/heads/$(PG_BRANCH).zip
125-
unzip $(PGDIRZIP)
126-
mv $(root_dir)/postgres-$(PG_BRANCH) $(PGDIR)
119+
curl -o $(PGDIRBZ2) https://ftp.postgresql.org/pub/source/v$(PG_VERSION)/postgresql-$(PG_VERSION).tar.bz2
120+
tar -xjf $(PGDIRBZ2)
121+
mv $(root_dir)/postgresql-$(PG_VERSION) $(PGDIR)
127122
cd $(PGDIR); patch -p1 < $(root_dir)/patches/01_parser_additional_param_ref_support.patch
128123
cd $(PGDIR); patch -p1 < $(root_dir)/patches/03_lexer_track_yyllocend.patch
129124
cd $(PGDIR); patch -p1 < $(root_dir)/patches/04_lexer_comments_as_tokens.patch
@@ -133,6 +128,7 @@ $(PGDIR):
133128
cd $(PGDIR); patch -p1 < $(root_dir)/patches/08_avoid_zero_length_delimiter_in_regression_tests.patch
134129
cd $(PGDIR); patch -p1 < $(root_dir)/patches/09_allow_param_junk.patch
135130
cd $(PGDIR); patch -p1 < $(root_dir)/patches/10_avoid_namespace_hashtab_impl_gen.patch
131+
cd $(PGDIR); patch -p1 < $(root_dir)/patches/11_ifndef_namedatalen.patch
136132
cd $(PGDIR); ./configure $(PG_CONFIGURE_FLAGS)
137133
cd $(PGDIR); make -C src/pl/plpgsql/src pl_gram.h plerrcodes.h pl_reserved_kwlist_d.h pl_unreserved_kwlist_d.h
138134
cd $(PGDIR); make -C src/port pg_config_paths.h
@@ -241,14 +237,15 @@ examples/normalize_error: examples/normalize_error.c $(ARLIB)
241237
examples/simple_plpgsql: examples/simple_plpgsql.c $(ARLIB)
242238
$(CC) $(TEST_CFLAGS) -o $@ -g examples/simple_plpgsql.c $(ARLIB) $(TEST_LDFLAGS)
243239

244-
TESTS = test/complex test/concurrency test/deparse test/fingerprint test/fingerprint_opts test/normalize test/normalize_utility test/parse test/parse_opts test/parse_protobuf test/parse_protobuf_opts test/parse_plpgsql test/scan test/split
240+
TESTS = test/complex test/concurrency test/deparse test/fingerprint test/fingerprint_opts test/is_utility_stmt test/normalize test/normalize_utility test/parse test/parse_opts test/parse_protobuf test/parse_protobuf_opts test/parse_plpgsql test/scan test/split test/summary test/summary_truncate
245241
test: $(TESTS)
246242
ifeq ($(VALGRIND),1)
247243
$(VALGRIND_MEMCHECK) test/complex || (cat test/valgrind.log && false)
248244
$(VALGRIND_MEMCHECK) test/concurrency || (cat test/valgrind.log && false)
249245
$(VALGRIND_MEMCHECK) test/deparse || (cat test/valgrind.log && false)
250246
$(VALGRIND_MEMCHECK) test/fingerprint || (cat test/valgrind.log && false)
251247
$(VALGRIND_MEMCHECK) test/fingerprint_opts || (cat test/valgrind.log && false)
248+
$(VALGRIND_MEMCHECK) test/is_utility_stmt || (cat test/valgrind.log && false)
252249
$(VALGRIND_MEMCHECK) test/normalize || (cat test/valgrind.log && false)
253250
$(VALGRIND_MEMCHECK) test/normalize_utility || (cat test/valgrind.log && false)
254251
$(VALGRIND_MEMCHECK) test/parse || (cat test/valgrind.log && false)
@@ -257,6 +254,8 @@ ifeq ($(VALGRIND),1)
257254
$(VALGRIND_MEMCHECK) test/parse_protobuf_opts || (cat test/valgrind.log && false)
258255
$(VALGRIND_MEMCHECK) test/scan || (cat test/valgrind.log && false)
259256
$(VALGRIND_MEMCHECK) test/split || (cat test/valgrind.log && false)
257+
$(VALGRIND_MEMCHECK) test/summary || (cat test/valgrind.log && false)
258+
$(VALGRIND_MEMCHECK) test/summary_truncate || (cat test/valgrind.log && false)
260259
# Output-based tests
261260
$(VALGRIND_MEMCHECK) test/parse_plpgsql || (cat test/valgrind.log && false)
262261
diff -Naur test/plpgsql_samples.expected.json test/plpgsql_samples.actual.json
@@ -266,6 +265,7 @@ else
266265
test/deparse
267266
test/fingerprint
268267
test/fingerprint_opts
268+
test/is_utility_stmt
269269
test/normalize
270270
test/normalize_utility
271271
test/parse
@@ -274,6 +274,8 @@ else
274274
test/parse_protobuf_opts
275275
test/scan
276276
test/split
277+
test/summary
278+
test/summary_truncate
277279
# Output-based tests
278280
test/parse_plpgsql
279281
diff -Naur test/plpgsql_samples.expected.json test/plpgsql_samples.actual.json
@@ -297,6 +299,10 @@ test/fingerprint_opts: test/fingerprint_opts.c test/fingerprint_opts_tests.c $(A
297299
# We have "-Isrc/" because this test uses pg_query_fingerprint_with_opts
298300
$(CC) $(TEST_CFLAGS) -o $@ -Isrc/ test/fingerprint_opts.c $(ARLIB) $(TEST_LDFLAGS)
299301

302+
test/is_utility_stmt: test/framework/main.c test/is_utility_stmt.c $(ARLIB)
303+
# We have "-Isrc/postgres/include" because this test uses pg_query_summary_direct
304+
$(CC) $(TEST_CFLAGS) -o $@ -Isrc/postgres/include test/framework/main.c test/is_utility_stmt.c $(ARLIB) $(TEST_LDFLAGS)
305+
300306
test/normalize: test/normalize.c test/normalize_tests.c $(ARLIB)
301307
$(CC) $(TEST_CFLAGS) -o $@ test/normalize.c $(ARLIB) $(TEST_LDFLAGS)
302308

@@ -306,6 +312,14 @@ test/normalize_utility: test/normalize_utility.c test/normalize_utility_tests.c
306312
test/parse: test/parse.c test/parse_tests.c $(ARLIB)
307313
$(CC) $(TEST_CFLAGS) -o $@ test/parse.c $(ARLIB) $(TEST_LDFLAGS)
308314

315+
test/summary: test/framework/main.c test/summary.c test/summary_tests.c test/summary_tests_list.c $(ARLIB)
316+
# We have "-Isrc/postgres/include" because this test uses pg_query_summary_direct
317+
$(CC) $(TEST_CFLAGS) -o $@ -Isrc/postgres/include test/framework/main.c test/summary.c $(ARLIB) $(TEST_LDFLAGS)
318+
319+
test/summary_truncate: test/framework/main.c test/summary_truncate.c $(ARLIB)
320+
# We have "-Isrc/postgres/include" because this test uses pg_query_summary_direct
321+
$(CC) $(TEST_CFLAGS) -o $@ -Isrc/postgres/include test/framework/main.c test/summary_truncate.c $(ARLIB) $(TEST_LDFLAGS)
322+
309323
test/parse_opts: test/parse_opts.c test/parse_opts_tests.c $(ARLIB)
310324
$(CC) $(TEST_CFLAGS) -o $@ test/parse_opts.c $(ARLIB) $(TEST_LDFLAGS)
311325

@@ -336,4 +350,5 @@ install: $(ARLIB) $(SOLIB)
336350
$(LN_S) $(SOLIBVER) "$(DESTDIR)"$(libdir)/$(SOLIB)
337351
$(INSTALL) -d "$(DESTDIR)"$(includedir)/$(TARGET)
338352
$(INSTALL) -m 644 pg_query.h "$(DESTDIR)"$(includedir)/pg_query.h
353+
$(INSTALL) -m 644 postgres_deparse.h "$(DESTDIR)"$(includedir)/postgres_deparse.h
339354
$(INSTALL) -m 644 protobuf/pg_query.proto "$(DESTDIR)"$(includedir)/$(TARGET)/pg_query.proto

c_src/libpg_query/Makefile.msvc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,21 @@ examples/normalize_error: examples/normalize_error.c $(ARLIB)
5050
examples/simple_plpgsql: examples/simple_plpgsql.c $(ARLIB)
5151
$(CC) $(CFLAGS) -o $@ examples/simple_plpgsql.c $(ARLIB)
5252

53-
TESTS = test/deparse test/fingerprint test/fingerprint_opts test/normalize test/parse test/parse_opts test/parse_protobuf test/parse_protobuf_opts test/parse_plpgsql test/scan test/split
53+
TESTS = test/deparse test/fingerprint test/fingerprint_opts test/is_utility_stmt test/normalize test/parse test/parse_opts test/parse_protobuf test/parse_protobuf_opts test/parse_plpgsql test/scan test/split test/summary test/summary_truncate
5454
test: $(TESTS)
5555
.\test\deparse
5656
.\test\fingerprint
5757
.\test\fingerprint_opts
58+
.\test\is_utility_stmt
5859
.\test\normalize
5960
.\test\parse
6061
.\test\parse_opts
6162
.\test\parse_protobuf
6263
.\test\parse_protobuf_opts
6364
.\test\scan
6465
.\test\split
66+
.\test\summary
67+
.\test\summary_truncate
6568

6669
# Doesn't work because of C2026: string too big, trailing characters truncated
6770
#test/complex: test/complex.c $(ARLIB)
@@ -83,6 +86,9 @@ test/fingerprint_opts: test/fingerprint_opts.c test/fingerprint_opts_tests.c $(A
8386
# We have "-Isrc/" because this test uses pg_query_fingerprint_with_opts
8487
$(CC) $(CFLAGS) -o $@ -Isrc/ test/fingerprint_opts.c $(ARLIB)
8588

89+
test/is_utility_stmt: test/framework/main.c test/is_utility_stmt.c $(ARLIB)
90+
$(CC) $(CFLAGS) -o $@ test/framework/main.c test/is_utility_stmt.c $(ARLIB)
91+
8692
test/normalize: test/normalize.c test/normalize_tests.c $(ARLIB)
8793
$(CC) $(CFLAGS) -o $@ test/normalize.c $(ARLIB)
8894

@@ -106,3 +112,9 @@ test/scan: test/scan.c test/scan_tests.c $(ARLIB)
106112

107113
test/split: test/split.c test/split_tests.c $(ARLIB)
108114
$(CC) $(CFLAGS) -o $@ test/split.c $(ARLIB)
115+
116+
test/summary: test/framework/main.c test/summary.c test/summary_tests.c test/summary_tests_list.c $(ARLIB)
117+
$(CC) $(CFLAGS) -o $@ test/framework/main.c test/summary.c $(ARLIB)
118+
119+
test/summary_truncate: test/framework/main.c test/summary_truncate.c $(ARLIB)
120+
$(CC) $(CFLAGS) -o $@ test/framework/main.c test/summary_truncate.c $(ARLIB)

c_src/libpg_query/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ int main() {
4444
printf("%s\n", result.parse_tree);
4545

4646
pg_query_free_parse_result(result);
47+
48+
return 0;
4749
}
4850
```
4951

@@ -57,7 +59,7 @@ This will output the parse tree (whitespace adjusted here for better readability
5759

5860
```json
5961
{
60-
"version": 170004,
62+
"version": 170007,
6163
"stmts": [
6264
{
6365
"stmt": {
@@ -110,9 +112,9 @@ int main() {
110112
const char *input = "SELECT update AS left /* comment */ FROM between";
111113

112114
result = pg_query_scan(input);
113-
scan_result = pg_query__scan_result__unpack(NULL, result.pbuf.len, (void *) result.pbuf.data);
115+
scan_result = pg_query__scan_result__unpack(NULL, result.pbuf.len, (const uint8_t *) result.pbuf.data);
114116

115-
printf(" version: %d, tokens: %ld, size: %d\n", scan_result->version, scan_result->n_tokens, result.pbuf.len);
117+
printf(" version: %d, tokens: %ld, size: %zu\n", scan_result->version, scan_result->n_tokens, result.pbuf.len);
116118
for (size_t j = 0; j < scan_result->n_tokens; j++) {
117119
scan_token = scan_result->tokens[j];
118120
token_kind = protobuf_c_enum_descriptor_get_value(&pg_query__token__descriptor, scan_token->token);
@@ -130,7 +132,7 @@ int main() {
130132
This will output the following:
131133

132134
```
133-
version: 170004, tokens: 7, size: 77
135+
version: 170007, tokens: 7, size: 77
134136
"SELECT" = [ 0, 6, SELECT, RESERVED_KEYWORD ]
135137
"update" = [ 7, 13, UPDATE, UNRESERVED_KEYWORD ]
136138
"AS" = [ 14, 16, AS, RESERVED_KEYWORD ]
@@ -174,6 +176,8 @@ int main() {
174176
printf("%s\n", result.fingerprint_str);
175177

176178
pg_query_free_fingerprint_result(result);
179+
180+
return 0;
177181
}
178182
```
179183

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h
2+
index a1a93ad..c978d76 100644
3+
--- a/src/include/pg_config_manual.h
4+
+++ b/src/include/pg_config_manual.h
5+
@@ -26,7 +26,9 @@
6+
*
7+
* Changing this requires an initdb.
8+
*/
9+
+#ifndef NAMEDATALEN
10+
#define NAMEDATALEN 64
11+
+#endif
12+
13+
/*
14+
* Maximum number of arguments to a function.

0 commit comments

Comments
 (0)