pg_query 4.2.0 → 4.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -2
- data/README.md +29 -33
- data/Rakefile +4 -4
- data/ext/pg_query/extconf.rb +3 -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 +10665 -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: ea8fb56217063eac1d411d1939edb4e0aa1319657a72d359ce09b76cc6c3e7cd
|
4
|
+
data.tar.gz: 783e06aa36da1192a14500ccdefcba25e179fff0178be18b8724eca51d23ebbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4cc8dcdc572277b2c667f4b7df253a0ba123b3fbac1eb82be8ab3cacd419875393d6ca1d4a7cc74dde2d9f8d45c42e3e453f36a35622d67e3b57ebc95af248e
|
7
|
+
data.tar.gz: 020ec80cfc1e9f22a679db3298e8cb719cf52acd50a9692f76771c7039c258ebe9b0b5574742d974e82c8ce61a509387a4a89727807ce9cdd44ddddf62f0d225
|
data/CHANGELOG.md
CHANGED
@@ -4,17 +4,42 @@
|
|
4
4
|
|
5
5
|
* ...
|
6
6
|
|
7
|
-
|
7
|
+
|
8
|
+
## 4.2.2 2023-07-07
|
9
|
+
|
10
|
+
* Update to libpg_query 15-4.2.2
|
11
|
+
- Deparser: Add support for multi-statement CREATE PROCEDURE definitions
|
12
|
+
- Deparser: Correctly quote identifier in ALTER TABLE ... ADD CONSTRAINT [x]
|
13
|
+
- Deparser: Add support for index fillfactor within CREATE TABLE, fix SHOW ALL
|
14
|
+
* Fix builds on FreeBSD ([#292](https://github.com/pganalyze/pg_query/pull/292))
|
15
|
+
- This was broken since 4.2.0, due to pg_query_ruby_freebsd.sym being removed by accident
|
16
|
+
|
17
|
+
|
18
|
+
## 4.2.1 2023-05-19
|
19
|
+
|
20
|
+
* Parse: Fix `ALTER INDEX my_index_name` to return `tables=[]` ([#285](https://github.com/pganalyze/pg_query/pull/285))
|
21
|
+
* Parse: Detect tables in a SELECT INTO clause as DDL tables ([#281](https://github.com/pganalyze/pg_query/pull/281))
|
22
|
+
* Add support for Ruby 3.2 ([#283](https://github.com/pganalyze/pg_query/pull/283))
|
23
|
+
* Bump up `google-protobuf` dependency to `>= 3.22.3`
|
24
|
+
- 3.22.0 or newer is required for Ruby 3.2 support
|
25
|
+
* Update to libpg_query 15-4.2.1
|
26
|
+
- Deparser: Handle INTERVAL correctly when used in SET statements
|
27
|
+
- Deparser: Ensure index names are quoted as identifiers
|
28
|
+
|
29
|
+
|
30
|
+
## 4.2.0 2023-02-08
|
8
31
|
|
9
32
|
* Update to libpg_query 15-4.2.0
|
10
33
|
- Update to PostgreSQL 15.1
|
11
34
|
|
12
|
-
|
35
|
+
|
36
|
+
## 2.2.1 2023-01-20
|
13
37
|
|
14
38
|
* Detect tables used in the query of a PREPARE statement ([#273](https://github.com/pganalyze/pg_query/pull/273))
|
15
39
|
* Expose recursive walk functionality via walk! ([#268](https://github.com/pganalyze/pg_query/pull/268))
|
16
40
|
* Retain schema in name when parsing out functions ([#272](https://github.com/pganalyze/pg_query/pull/272))
|
17
41
|
|
42
|
+
|
18
43
|
## 2.2.0 2022-11-02
|
19
44
|
|
20
45
|
* 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.2'.freeze
|
9
|
+
LIB_PG_QUERY_SHA256SUM = '03d6631b4a5ea9cc26cb2569e0303b9cce2bc1c6b6e1488f5ab9d63e6bd5346d'.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
|
|