pg_query 4.2.0 → 4.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -2
- data/README.md +29 -33
- data/Rakefile +4 -4
- data/ext/pg_query/extconf.rb +3 -1
- data/ext/pg_query/include/pg_config.h +2 -1
- data/ext/pg_query/pg_query_deparse.c +1 -10587
- data/ext/pg_query/pg_query_ruby_freebsd.sym +2 -0
- data/ext/pg_query/postgres_deparse.c +10669 -0
- data/ext/pg_query/postgres_deparse.h +9 -0
- data/lib/pg_query/parse.rb +10 -1
- data/lib/pg_query/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ef3b405c38280a7d7fd951b9b2d181d4b54b7c650817227a8fa5e4e0e9a38d8
|
4
|
+
data.tar.gz: 4d76a4a3d25b847c2996613c761a5529f17e2e03d5f17257c39d02d8291e48b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c5790923fd334079f84eb70154b330ba8dd1c61b8a54acc4248dcf7327a1137d32a29127c9aa8d6a3e87b3d5bfb47169f628fd54afb94c94c167658d37a2083
|
7
|
+
data.tar.gz: 6c5954ddfd3c31dfeabb0747c505ed06094a892ac75e3de052aabb91f9edff3726d4c1f0d6da9324467d8ecf71434b92021f35cd6bb1e2ac1121684daafedf08
|
data/CHANGELOG.md
CHANGED
@@ -4,17 +4,48 @@
|
|
4
4
|
|
5
5
|
* ...
|
6
6
|
|
7
|
-
|
7
|
+
|
8
|
+
## 4.2.3 2023-08-04
|
9
|
+
|
10
|
+
* Update to libpg_query 15-4.2.3
|
11
|
+
- Fix builds when compiling with `glibc >= 2.38` [#203](https://github.com/pganalyze/libpg_query/pull/203)
|
12
|
+
- Deparser: Add support for COALESCE and other expressions in LIMIT clause [#199](https://github.com/pganalyze/libpg_query/pull/199)
|
13
|
+
|
14
|
+
## 4.2.2 2023-07-07
|
15
|
+
|
16
|
+
* Update to libpg_query 15-4.2.2
|
17
|
+
- Deparser: Add support for multi-statement CREATE PROCEDURE definitions
|
18
|
+
- Deparser: Correctly quote identifier in ALTER TABLE ... ADD CONSTRAINT [x]
|
19
|
+
- Deparser: Add support for index fillfactor within CREATE TABLE, fix SHOW ALL
|
20
|
+
* Fix builds on FreeBSD ([#292](https://github.com/pganalyze/pg_query/pull/292))
|
21
|
+
- This was broken since 4.2.0, due to pg_query_ruby_freebsd.sym being removed by accident
|
22
|
+
|
23
|
+
|
24
|
+
## 4.2.1 2023-05-19
|
25
|
+
|
26
|
+
* Parse: Fix `ALTER INDEX my_index_name` to return `tables=[]` ([#285](https://github.com/pganalyze/pg_query/pull/285))
|
27
|
+
* Parse: Detect tables in a SELECT INTO clause as DDL tables ([#281](https://github.com/pganalyze/pg_query/pull/281))
|
28
|
+
* Add support for Ruby 3.2 ([#283](https://github.com/pganalyze/pg_query/pull/283))
|
29
|
+
* Bump up `google-protobuf` dependency to `>= 3.22.3`
|
30
|
+
- 3.22.0 or newer is required for Ruby 3.2 support
|
31
|
+
* Update to libpg_query 15-4.2.1
|
32
|
+
- Deparser: Handle INTERVAL correctly when used in SET statements
|
33
|
+
- Deparser: Ensure index names are quoted as identifiers
|
34
|
+
|
35
|
+
|
36
|
+
## 4.2.0 2023-02-08
|
8
37
|
|
9
38
|
* Update to libpg_query 15-4.2.0
|
10
39
|
- Update to PostgreSQL 15.1
|
11
40
|
|
12
|
-
|
41
|
+
|
42
|
+
## 2.2.1 2023-01-20
|
13
43
|
|
14
44
|
* Detect tables used in the query of a PREPARE statement ([#273](https://github.com/pganalyze/pg_query/pull/273))
|
15
45
|
* Expose recursive walk functionality via walk! ([#268](https://github.com/pganalyze/pg_query/pull/268))
|
16
46
|
* Retain schema in name when parsing out functions ([#272](https://github.com/pganalyze/pg_query/pull/272))
|
17
47
|
|
48
|
+
|
18
49
|
## 2.2.0 2022-11-02
|
19
50
|
|
20
51
|
* Update to libpg_query 13-2.2.0 ([#264](https://github.com/pganalyze/pg_query/pull/264))
|
data/README.md
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
This Ruby extension uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parsetree.
|
4
4
|
|
5
|
-
In addition the extension allows you to normalize queries (replacing constant values with
|
5
|
+
In addition the extension allows you to normalize queries (replacing constant values with $n) and parse these normalized queries into a parsetree again.
|
6
6
|
|
7
7
|
When you build this extension, it builds parts of the PostgreSQL server source (see [libpg_query](https://github.com/pganalyze/libpg_query)), and then statically links it into this extension.
|
8
8
|
|
9
|
-
This
|
9
|
+
This may seem like a lot of complexity, but is the only reliable way of parsing all valid PostgreSQL queries.
|
10
10
|
|
11
11
|
You can find further examples and a longer rationale here: https://pganalyze.com/blog/parse-postgresql-queries-in-ruby.html
|
12
12
|
|
@@ -25,10 +25,10 @@ Due to compiling parts of PostgreSQL, installation might take a while on slower
|
|
25
25
|
```ruby
|
26
26
|
PgQuery.parse("SELECT 1")
|
27
27
|
|
28
|
-
=> #<PgQuery::ParserResult:
|
28
|
+
=> #<PgQuery::ParserResult:0x000000012000c438
|
29
29
|
@query="SELECT 1",
|
30
30
|
@tree=<PgQuery::ParseResult:
|
31
|
-
version:
|
31
|
+
version: 150001,
|
32
32
|
stmts: [
|
33
33
|
<PgQuery::RawStmt:
|
34
34
|
stmt: <PgQuery::Node:
|
@@ -41,10 +41,11 @@ PgQuery.parse("SELECT 1")
|
|
41
41
|
indirection: [],
|
42
42
|
val: <PgQuery::Node:
|
43
43
|
a_const: <PgQuery::A_Const:
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
isnull: false,
|
45
|
+
location: 7,
|
46
|
+
ival: <PgQuery::Integer:
|
47
|
+
ival: 1
|
48
|
+
>
|
48
49
|
>
|
49
50
|
>,
|
50
51
|
location: 7
|
@@ -53,6 +54,7 @@ PgQuery.parse("SELECT 1")
|
|
53
54
|
],
|
54
55
|
from_clause: [],
|
55
56
|
group_clause: [],
|
57
|
+
group_distinct: false,
|
56
58
|
window_clause: [],
|
57
59
|
values_lists: [],
|
58
60
|
sort_clause: [],
|
@@ -67,7 +69,12 @@ PgQuery.parse("SELECT 1")
|
|
67
69
|
>
|
68
70
|
]
|
69
71
|
>,
|
70
|
-
@warnings=[]
|
72
|
+
@warnings=[],
|
73
|
+
@tables=nil,
|
74
|
+
@aliases=nil,
|
75
|
+
@cte_names=nil,
|
76
|
+
@functions=nil
|
77
|
+
>
|
71
78
|
```
|
72
79
|
|
73
80
|
### Modifying a parsed query and turning it into SQL again
|
@@ -92,20 +99,12 @@ parsed_query.deparse
|
|
92
99
|
PgQuery.normalize("SELECT 1 FROM x WHERE y = 'foo'")
|
93
100
|
|
94
101
|
=> "SELECT $1 FROM x WHERE y = $2"
|
95
|
-
|
96
|
-
# Parsing a normalized query (pre-Postgres 10 style)
|
97
|
-
PgQuery.parse("SELECT ? FROM x WHERE y = ?")
|
98
|
-
|
99
|
-
=> #<PgQuery::ParserResult:0x00007fb69a97a5d8
|
100
|
-
@query="SELECT ? FROM x WHERE y = ?",
|
101
|
-
@tree=<PgQuery::ParseResult: ...>,
|
102
|
-
@warnings=[]>
|
103
102
|
```
|
104
103
|
|
105
104
|
### Extracting tables from a query
|
106
105
|
|
107
106
|
```ruby
|
108
|
-
PgQuery.parse("SELECT
|
107
|
+
PgQuery.parse("SELECT $1 FROM x JOIN y USING (id) WHERE z = $2").tables
|
109
108
|
|
110
109
|
=> ["x", "y"]
|
111
110
|
```
|
@@ -113,7 +112,7 @@ PgQuery.parse("SELECT ? FROM x JOIN y USING (id) WHERE z = ?").tables
|
|
113
112
|
### Extracting columns from a query
|
114
113
|
|
115
114
|
```ruby
|
116
|
-
PgQuery.parse("SELECT
|
115
|
+
PgQuery.parse("SELECT $1 FROM x WHERE x.y = $2 AND z = $3").filter_columns
|
117
116
|
|
118
117
|
=> [["x", "y"], [nil, "z"]]
|
119
118
|
```
|
@@ -130,7 +129,7 @@ PgQuery.parse("SELECT 2; --- comment").fingerprint
|
|
130
129
|
=> "50fde20626009aba"
|
131
130
|
|
132
131
|
# Faster fingerprint method that is implemented inside the native C library
|
133
|
-
PgQuery.fingerprint("SELECT
|
132
|
+
PgQuery.fingerprint("SELECT $1")
|
134
133
|
|
135
134
|
=> "50fde20626009aba"
|
136
135
|
```
|
@@ -140,7 +139,7 @@ PgQuery.fingerprint("SELECT ?")
|
|
140
139
|
```ruby
|
141
140
|
PgQuery.scan('SELECT 1 --comment')
|
142
141
|
|
143
|
-
=> [<PgQuery::ScanResult: version:
|
142
|
+
=> [<PgQuery::ScanResult: version: 150001, tokens: [
|
144
143
|
<PgQuery::ScanToken: start: 0, end: 6, token: :SELECT, keyword_kind: :RESERVED_KEYWORD>,
|
145
144
|
<PgQuery::ScanToken: start: 7, end: 8, token: :ICONST, keyword_kind: :NO_KEYWORD>,
|
146
145
|
<PgQuery::ScanToken: start: 9, end: 18, token: :SQL_COMMENT, keyword_kind: :NO_KEYWORD>]>,
|
@@ -177,20 +176,15 @@ First, some of the tree nodes are frozen. You can replace them, but you cannot m
|
|
177
176
|
Second, table rewriting is a bit more nuanced than this example. While this will rewrite the table names, it will
|
178
177
|
not correctly handle all CTEs, or rewrite columns with explicit table names.
|
179
178
|
|
180
|
-
## Differences from Upstream PostgreSQL
|
181
|
-
|
182
|
-
This gem is based on [libpg_query](https://github.com/pganalyze/libpg_query),
|
183
|
-
which uses the latest stable PostgreSQL version, but with a patch applied
|
184
|
-
to support parsing normalized queries containing `?` replacement characters.
|
185
|
-
|
186
179
|
## Supported Ruby Versions
|
187
180
|
|
188
181
|
Currently tested and officially supported Ruby versions:
|
189
182
|
|
190
|
-
* CRuby 2.5
|
191
183
|
* CRuby 2.6
|
192
184
|
* CRuby 2.7
|
193
185
|
* CRuby 3.0
|
186
|
+
* CRuby 3.1
|
187
|
+
* CRuby 3.2
|
194
188
|
|
195
189
|
Not supported:
|
196
190
|
|
@@ -214,7 +208,7 @@ Once that is done, follow the following steps:
|
|
214
208
|
|
215
209
|
## Resources
|
216
210
|
|
217
|
-
See [libpg_query](https://github.com/pganalyze/libpg_query/blob/
|
211
|
+
See [libpg_query](https://github.com/pganalyze/libpg_query/blob/15-latest/README.md#resources) for pg_query in other languages, as well as products/tools built on pg_query.
|
218
212
|
|
219
213
|
## Original Author
|
220
214
|
|
@@ -228,8 +222,10 @@ See [libpg_query](https://github.com/pganalyze/libpg_query/blob/13-latest/README
|
|
228
222
|
|
229
223
|
## License
|
230
224
|
|
231
|
-
|
232
|
-
|
225
|
+
PostgreSQL server source code, used under the [PostgreSQL license](https://www.postgresql.org/about/licence/).<br>
|
226
|
+
Portions Copyright (c) 1996-2023, The PostgreSQL Global Development Group<br>
|
227
|
+
Portions Copyright (c) 1994, The Regents of the University of California
|
233
228
|
|
234
|
-
|
235
|
-
Copyright (c)
|
229
|
+
All other parts are licensed under the 3-clause BSD license, see LICENSE file for details.<br>
|
230
|
+
Copyright (c) 2015, Lukas Fittl <lukas@fittl.com><br>
|
231
|
+
Copyright (c) 2016-2023, Duboce Labs, Inc. (pganalyze) <team@pganalyze.com>
|
data/Rakefile
CHANGED
@@ -5,8 +5,8 @@ require 'rspec/core/rake_task'
|
|
5
5
|
require 'rubocop/rake_task'
|
6
6
|
require 'open-uri'
|
7
7
|
|
8
|
-
LIB_PG_QUERY_TAG = '15-4.2.
|
9
|
-
LIB_PG_QUERY_SHA256SUM = '
|
8
|
+
LIB_PG_QUERY_TAG = '15-4.2.3'.freeze
|
9
|
+
LIB_PG_QUERY_SHA256SUM = '8b820d63442b1677ce4f0df2a95b3fafdbc520a82901def81217559ec4df9e6b'.freeze
|
10
10
|
|
11
11
|
Rake::ExtensionTask.new 'pg_query' do |ext|
|
12
12
|
ext.lib_dir = 'lib/pg_query'
|
@@ -55,7 +55,7 @@ task :update_source do
|
|
55
55
|
# Backup important files from ext dir
|
56
56
|
system("rm -fr #{extbakdir}")
|
57
57
|
system("mkdir -p #{extbakdir}")
|
58
|
-
system("cp -a #{extdir}/pg_query_ruby.
|
58
|
+
system("cp -a #{extdir}/pg_query_ruby{.c,.sym,_freebsd.sym} #{extdir}/extconf.rb #{extbakdir}")
|
59
59
|
|
60
60
|
FileUtils.rm_rf extdir
|
61
61
|
|
@@ -85,5 +85,5 @@ task :update_source do
|
|
85
85
|
# Other support files
|
86
86
|
system("cp -a #{libdir}/testdata/* #{testfilesdir}")
|
87
87
|
# Copy back the custom ext files
|
88
|
-
system("cp -a #{extbakdir}/pg_query_ruby.
|
88
|
+
system("cp -a #{extbakdir}/pg_query_ruby{.c,.sym,_freebsd.sym} #{extbakdir}/extconf.rb #{extdir}")
|
89
89
|
end
|
data/ext/pg_query/extconf.rb
CHANGED
@@ -7,7 +7,9 @@ require 'pathname'
|
|
7
7
|
|
8
8
|
$objs = Dir.glob(File.join(__dir__, '*.c')).map { |f| Pathname.new(f).sub_ext('.o').to_s }
|
9
9
|
|
10
|
-
|
10
|
+
# -Wno-deprecated-non-prototype avoids warnings on Clang 15.0+, this can be removed in Postgres 16:
|
11
|
+
# https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=1c27d16e6e5c1f463bbe1e9ece88dda811235165
|
12
|
+
$CFLAGS << " -fvisibility=hidden -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-protector -Wno-unused-function -Wno-unused-variable -Wno-clobbered -Wno-sign-compare -Wno-discarded-qualifiers -Wno-deprecated-non-prototype -Wno-unknown-warning-option -g"
|
11
13
|
|
12
14
|
$INCFLAGS = "-I#{File.join(__dir__, 'include')} " + $INCFLAGS
|
13
15
|
|
@@ -1032,6 +1032,7 @@
|
|
1032
1032
|
#undef HAVE__GET_CPUID
|
1033
1033
|
#undef USE_ARMV8_CRC32C
|
1034
1034
|
#undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK
|
1035
|
-
#
|
1035
|
+
#include <stdlib.h>
|
1036
|
+
#if defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__GLIBC__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) || __GLIBC__ > 2))
|
1036
1037
|
#define HAVE_STRCHRNUL
|
1037
1038
|
#endif
|