pg_query 2.0.1 → 2.1.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +220 -114
  3. data/README.md +12 -0
  4. data/Rakefile +6 -21
  5. data/ext/pg_query/extconf.rb +5 -2
  6. data/ext/pg_query/include/c.h +12 -0
  7. data/ext/pg_query/include/executor/executor.h +6 -0
  8. data/ext/pg_query/include/nodes/execnodes.h +9 -6
  9. data/ext/pg_query/include/nodes/pathnodes.h +1 -1
  10. data/ext/pg_query/include/optimizer/paths.h +8 -0
  11. data/ext/pg_query/include/pg_config.h +10 -6
  12. data/ext/pg_query/include/pg_config_manual.h +7 -0
  13. data/ext/pg_query/include/pg_query.h +2 -2
  14. data/ext/pg_query/include/pg_query_outfuncs_defs.c +1 -0
  15. data/ext/pg_query/include/pg_query_readfuncs_defs.c +1 -0
  16. data/ext/pg_query/include/protobuf/pg_query.pb-c.h +472 -467
  17. data/ext/pg_query/include/protobuf-c/protobuf-c.h +7 -3
  18. data/ext/pg_query/include/protobuf-c.h +7 -3
  19. data/ext/pg_query/include/utils/array.h +1 -0
  20. data/ext/pg_query/include/utils/lsyscache.h +1 -0
  21. data/ext/pg_query/include/utils/probes.h +57 -57
  22. data/ext/pg_query/pg_query.pb-c.c +502 -487
  23. data/ext/pg_query/pg_query_deparse.c +33 -21
  24. data/ext/pg_query/pg_query_fingerprint.c +123 -33
  25. data/ext/pg_query/pg_query_fingerprint.h +3 -1
  26. data/ext/pg_query/pg_query_normalize.c +222 -61
  27. data/ext/pg_query/pg_query_parse_plpgsql.c +21 -1
  28. data/ext/pg_query/pg_query_ruby.sym +1 -0
  29. data/ext/pg_query/protobuf-c.c +34 -27
  30. data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +36 -0
  31. data/ext/pg_query/src_common_hashfn.c +420 -0
  32. data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +1 -1
  33. data/lib/pg_query/filter_columns.rb +3 -1
  34. data/lib/pg_query/fingerprint.rb +1 -3
  35. data/lib/pg_query/parse.rb +101 -46
  36. data/lib/pg_query/pg_query_pb.rb +1385 -1383
  37. data/lib/pg_query/truncate.rb +12 -4
  38. data/lib/pg_query/version.rb +1 -1
  39. data/lib/pg_query.rb +0 -1
  40. metadata +8 -8
  41. data/lib/pg_query/json_field_names.rb +0 -1402
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5f97de1d1113193f804264c63e29434831dbec88c917471a64b93302308310e
4
- data.tar.gz: fbb5024c13381a02b3706bd9366f62f2e499a8afb30f25f5dfb4ae15723ae2a6
3
+ metadata.gz: b4db477ee95910b6c5d8e6c4e5f86c64cc985c0812cc461c017f652754848be1
4
+ data.tar.gz: 1167f0524fe8a23b19ee1beef4400cf5f0f817ba64f7d1893ac3d8ddb36ad0ce
5
5
  SHA512:
6
- metadata.gz: a4b80ec2176046a6f6f99cb9a053f5dd5cc10dfc0bed7f98276b46088e054e33da6efb1d7e2d1fc52264b2a915d0048007b3a800507a9eb58da460bfe4bedcd3
7
- data.tar.gz: 174fd09a8ee19b437d4601cfe544a8aa25cf88d6c38a1aa81814f8a59c54a4cbb0f6497d1af7fb4b8034356546f35f1841d875be3b434136c984ec0747c1e1e2
6
+ metadata.gz: 40d3c6157fc68c041f04bf9adcd6a6b018a821c45e877729ee1f657d97a1cea7d9b686ca2802c4dc56a21daae370433d8c96efb36f95a2a2a31f251307536c3d
7
+ data.tar.gz: 1ee0b3527a02b0e81c9177b37de943b51fe6b0f5ded846d298a659061133b3b76d25b5f76059dc5568484bca6939421b3e7d8c05e94d95f3f4a10d493a2301d6
data/CHANGELOG.md CHANGED
@@ -1,8 +1,89 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ * ...
6
+
7
+ ## 2.1.1 2021-10-13
8
+
9
+ * Update to libpg_query 13-2.1.0 ([#230](https://github.com/pganalyze/pg_query/pull/230))
10
+ - Normalize: add funcname error object
11
+ - Normalize: Match GROUP BY against target list and re-use param refs
12
+ - PL/pgSQL: Setup namespace items for parameters, support RECORD types
13
+ - This significantly improves parsing for PL/pgSQL functions, to the extent
14
+ that most functions should now parse successfully
15
+ - Normalize: Don't modify constants in TypeName typmods/arrayBounds fields
16
+ - This matches how pg_stat_statement behaves, and avoids causing parsing
17
+ errors on the normalized statement
18
+ - Don't fail builds on systems that have strchrnul support (FreeBSD)
19
+ * Fix build on FreeBSD ([#222](https://github.com/pganalyze/pg_query/pull/222))
20
+ * Add workaround for Ruby garbage collection bug ([#227](https://github.com/pganalyze/pg_query/pull/227))
21
+ - The Ruby interpreter has a bug in `String#concat` where the appended
22
+ array may be garbage collected prematurely because the compiler
23
+ optimized out a Ruby stack variable. We now call `to_ary` on the
24
+ Protobuf object to ensure the array lands on the Ruby stack so the
25
+ garbage collector sees it.
26
+ - The real fix in the interpreter is described in
27
+ https://bugs.ruby-lang.org/issues/18140#note-2, but most current Ruby
28
+ interpreters won't have this fix for some time.
29
+ * Table/function extraction: Support subselects and LATERAL better ([#229](https://github.com/pganalyze/pg_query/pull/229))
30
+ - This reworks the parsing logic so we don't ignore certain kinds of
31
+ subselects.
32
+
33
+
34
+ ## 2.1.0 2021-07-04
35
+
36
+ * Update to libpg_query 13-2.0.6
37
+ - Update to Postgres 13.3 patch release
38
+ - Normalize: Don't touch "GROUP BY 1" and "ORDER BY 1" expressions, keep original text
39
+ - Fingerprint: Cache list item hashes to fingerprint complex queries faster
40
+ - Deparser: Emit the RangeVar catalogname if present
41
+ - Fix crash in pg_scan function when encountering backslash escapes
42
+ * Support extracting functions from a parsed query ([#147](https://github.com/pganalyze/pg_query/pull/147))
43
+ - Adds new `functions`, `ddl_functions` and `call_functions` methods
44
+ - Note that functions are identified by their name only, not their full type definition,
45
+ since raw query parsetrees don't contain sufficient data to identify the types of
46
+ arguments when functions are called
47
+ * Relax google-protobuf dependency ([#213](https://github.com/pganalyze/pg_query/pull/213))
48
+ * Update google-protobuf to 3.17.1 ([#212](https://github.com/pganalyze/pg_query/pull/212))
49
+ - google-protobuf 3.15.x has a bug that causes a seg fault in Ruby under
50
+ certain conditions (https://github.com/protocolbuffers/protobuf/pull/8639). Use
51
+ google-protobuf 3.17.1 instead.
52
+ * Use Protobuf definition for determining JSON field names
53
+ - Note you may see a breaking change if you were using `PgQuery::ParseResult.encode_json`
54
+ to map the protobuf result to JSON, since this now respects the intended JSON names
55
+ from the Proto3 definition (instead of the differently formatted Protobuf field names)
56
+ * Rakefile: Fix "rake clean" by using CLEAN.include instead of CLEAN.<<
57
+ * Find tables inside COALESCE/MIN/MAX functions, UPDATE FROM list
58
+ * Extconf: Add library include path using $INCFLAGS, list it first
59
+ - This ensures any system installed libpg_query gets considered after
60
+ the bundled libpg_query, avoiding errors where the wrong header files
61
+ are used.
62
+
63
+
64
+ ## 2.0.3 2021-04-05
65
+
66
+ * Update to libpg_query 13-2.0.4
67
+ - Normalize: Fix handling of two subsequent DefElem elements (avoids crash)
68
+ - Deparser: Fix crash in CopyStmt with HEADER or FREEZE inside WITH parens
69
+
70
+
71
+ ## 2.0.2 2021-03-31
72
+
73
+ * `COALESCE` arguments are now included in `#filter_columns`
74
+ * Improve error message for protobuf parse failures
75
+ * Extconf: Fix object path regexp
76
+ - This accidentally replaced `.c` in the wrong parts of the path in some cases,
77
+ causing build failures
78
+ * Update to libpg_query 13-2.0.2
79
+ - Fix ARM builds: Avoid dependency on cpuid.h header
80
+ - Simplify deparser of TableLikeClause
81
+ - Fix asprintf warnings by ensuring _GNU_SOURCE is set early enough
82
+
83
+
3
84
  ## 2.0.1 2021-03-18
4
85
 
5
- * Fix Gem spec to correctly reference include files
86
+ * Fix gemspec to correctly reference include files
6
87
  - This would have shown as a build failure when using the published `2.0.0` gem
7
88
 
8
89
 
@@ -19,23 +100,23 @@
19
100
  * Use new deparser maintained directly in libpg_query
20
101
  * This replaces the complete Ruby deparser with a new, more complete deparser
21
102
  that is directly maintained in libpg_query. Further deparser improvements
22
- should be directly contributed to [libpg_query](https://github.com/pganalyze/libpg_query)
23
- * Tables helper: Return more details through "tables_with_details" method
24
- * This is renamed from the previously badly named "tables_with_types"
103
+ should be directly contributed to [libpg_query]
104
+ * Tables helper: Return more details through `#tables_with_details` method
105
+ * This is renamed from the previously badly named `#tables_with_types`
25
106
  method. Note that this change should not affect the output of the
26
- primary "tables" helper.
107
+ primary `tables` helper.
27
108
  * Replace on-demand libpg_query source download with bundled source code
28
109
  * Its unnecessary to download the source on-demand, and makes this more
29
110
  complex than it needs to be. Instead, introduce a new "update_source" rake
30
111
  task that can be called to refresh the source for a specified revision.
31
112
  * Re-implement smart truncation without requiring a special node type
32
- * This ensures the truncate method works with the new deparser, without
113
+ * This ensures the `#truncate` method works with the new deparser, without
33
114
  the C level code needing to know about it. We may add it in the C library
34
115
  in the future for edge cases that can't be covered by this slightly
35
116
  hack-ish approach, but for now this avoids unnecessary C library
36
117
  deparser modifications with non-standard node types.
37
- * Update Ruby finterprinting to new fingerprint format and XXH3 hash
38
- * Note that its recommended to use PgQuery.fingerprint for performance
118
+ * Update Ruby fingerprinting to new fingerprint format and XXH3 hash
119
+ * Note that its recommended to use `PgQuery.fingerprint` for performance
39
120
  reasons, but when the tree has been modified, it can be convenient to
40
121
  run a Ruby-side fingerprint instead of the C-based one that is faster.
41
122
 
@@ -44,25 +125,25 @@
44
125
 
45
126
  * Incorporate newer libpg_query updates in 10-1.0.3 and 10-1.0.4
46
127
  * Adds support for running on ARM
47
- * Fixes asprintf warning during builds
128
+ * Fixes an asprintf warning during builds
48
129
  * Updates to newer Postgres 10 patch release (10.15)
49
- * Deparsing improvements by [@emin100](https://github.com/emin100)
50
- * Add support for additional DROP statements (#147)
51
- * Fix CREATE TABLE AS - Support without TEMP, Add ON COMMIT (#149)
52
- * Empty target list support (#156)
53
- * UNION parentheses (#158)
54
- * OVERLAY keyword function (#161)
55
- * Array indirection (#162)
56
- * ARRAY functions (#163)
57
- * Correctly handle column names that need escaping in INSERT and UPDATE statements (#164)
58
- * INSERT INTO ON CONFLICT (#166)
59
- * LATERAL JOIN (#168)
60
- * UPDATE FROM clause (#170)
61
- * SELECT aggregate FILTER (#175)
62
- * INTERSECT operator (#176)
63
- * Deparsing: Improve handling of boolean type casts [@himanshu-pro](https://github.com/himanshu-pro) & [@emin100](https://github.com/emin100)
64
- * `tables` method: Find tables in the subquery of CREATE TABLE AS (#172) [@Tassosb](https://github.com/Tassosb)
65
- * Support Ruby 3.0, verify SHA256 checksum of downloaded libpg_query (#178) [@stanhu](https://github.com/stanhu)
130
+ * Deparsing improvements by [@emin100]
131
+ * Add support for additional DROP statements ([#147](https://github.com/pganalyze/pg_query/pull/147))
132
+ * Fix `CREATE TABLE AS` - Support without `TEMP`, Add `ON COMMIT` ([#149](https://github.com/pganalyze/pg_query/pull/149))
133
+ * Empty target list support ([#156](https://github.com/pganalyze/pg_query/pull/156))
134
+ * `UNION` parentheses ([#158](https://github.com/pganalyze/pg_query/pull/158))
135
+ * `OVERLAY` keyword function ([#161](https://github.com/pganalyze/pg_query/pull/161))
136
+ * Array indirection ([#162](https://github.com/pganalyze/pg_query/pull/162))
137
+ * `ARRAY` functions ([#163](https://github.com/pganalyze/pg_query/pull/163))
138
+ * Correctly handle column names that need escaping in `INSERT` and `UPDATE` statements ([#164](https://github.com/pganalyze/pg_query/pull/164))
139
+ * `INSERT INTO ON CONFLICT` ([#166](https://github.com/pganalyze/pg_query/pull/166))
140
+ * `LATERAL JOIN` ([#168](https://github.com/pganalyze/pg_query/pull/168))
141
+ * `UPDATE FROM` clause ([#170](https://github.com/pganalyze/pg_query/pull/170))
142
+ * `SELECT` aggregate `FILTER` ([#175](https://github.com/pganalyze/pg_query/pull/175))
143
+ * `INTERSECT` operator ([#176](https://github.com/pganalyze/pg_query/pull/176))
144
+ * Deparsing: Improve handling of boolean type casts [@himanshu-pro] & [@emin100]
145
+ * `tables` method: Find tables in the subquery of `CREATE TABLE AS` ([#172](https://github.com/pganalyze/pg_query/pull/172)) [@Tassosb]
146
+ * Support Ruby 3.0, verify SHA256 checksum of downloaded libpg_query ([#178](https://github.com/pganalyze/pg_query/pull/178)) [@stanhu]
66
147
  * Verify SHA256 checksum to guard against any malicious attempts to change the archive
67
148
  * Use `URI.open` to fix Ruby 3.0 support
68
149
 
@@ -78,69 +159,69 @@
78
159
 
79
160
  ## 1.1.1 2019-11-10
80
161
 
81
- * Deparsing improvements by [@emin100](https://github.com/emin100)
82
- * Deparse ILIKE, COLLATE and DISCARD (#133)
83
- * CREATE CAST (#136)
84
- * CREATE SCHEMA (#136)
85
- * UNION, UNION ALL and EXCEPT in SELECT queries (#136)
86
- * CREATE DOMAIN (#145)
87
- * Subquery indirection (#157)
88
- * Fix Type Cast Parentheses Problem (#152)
89
- * SELECT INTO (#151)
90
- * SET DEFAULT in INSERT INTO (#154)
91
- * REVOKE (#155)
92
- * PREPARE and EXECUTE (#148)
93
- * INSERT INTO ... RETURNING (#153)
94
- * Fix Alter .. RENAME SQL (#146)
95
- * Deparsing improvements by [@herwinw](https://github.com/herwinw)
96
- * Fix subquery in COPY in deparse (#112)
97
- * Function call indirection (#116)
98
- * Function without parameters (#117)
99
- * CREATE AGGREGATE
100
- * CREATE OPERATOR
101
- * CREATE TYPE
102
- * GRANT statements
103
- * DROP SCHEMA
104
- * Deparsing improvements by [@akiellor](https://github.com/akiellor)
105
- * Named window functions (#150)
106
- * Deparsing improvements by [@himanshu](https://github.com/himanshu)
107
- * Arguments in custom types (#143)
108
- * Use "double precision" instead of "double" type name (#139)
109
- * Use explicit -z flag to support OpenBSD tar (#134) [@sirn](https://github.com/sirn)
162
+ * Deparsing improvements by [@emin100]
163
+ * Deparse `ILIKE`, `COLLATE` and `DISCARD` ([#133](https://github.com/pganalyze/pg_query/pull/133))
164
+ * `CREATE CAST` ([#136](https://github.com/pganalyze/pg_query/pull/136))
165
+ * `CREATE SCHEMA` ([#136](https://github.com/pganalyze/pg_query/pull/136))
166
+ * `UNION`, `UNION ALL` and `EXCEPT` in `SELECT` queries ([#136](https://github.com/pganalyze/pg_query/pull/136))
167
+ * `CREATE DOMAIN` ([#145](https://github.com/pganalyze/pg_query/pull/145))
168
+ * Subquery indirection ([#157](https://github.com/pganalyze/pg_query/pull/157))
169
+ * Fix Type Cast Parentheses Problem ([#152](https://github.com/pganalyze/pg_query/pull/152))
170
+ * `SELECT INTO` ([#151](https://github.com/pganalyze/pg_query/pull/151))
171
+ * `SET DEFAULT` in `INSERT INTO` ([#154](https://github.com/pganalyze/pg_query/pull/154))
172
+ * `REVOKE` ([#155](https://github.com/pganalyze/pg_query/pull/155))
173
+ * `PREPARE` and `EXECUTE` ([#148](https://github.com/pganalyze/pg_query/pull/148))
174
+ * `INSERT INTO ... RETURNING` ([#153](https://github.com/pganalyze/pg_query/pull/153))
175
+ * Fix Alter .. `RENAME SQL` ([#146](https://github.com/pganalyze/pg_query/pull/146))
176
+ * Deparsing improvements by [@herwinw]
177
+ * Fix subquery in `COPY` in deparse ([#112](https://github.com/pganalyze/pg_query/pull/112))
178
+ * Function call indirection ([#116](https://github.com/pganalyze/pg_query/pull/116))
179
+ * Function without parameters ([#117](https://github.com/pganalyze/pg_query/pull/117))
180
+ * `CREATE AGGREGATE`
181
+ * `CREATE OPERATOR`
182
+ * `CREATE TYPE`
183
+ * `GRANT` statements
184
+ * `DROP SCHEMA`
185
+ * Deparsing improvements by [@akiellor]
186
+ * Named window functions ([#150](https://github.com/pganalyze/pg_query/pull/150))
187
+ * Deparsing improvements by [@himanshu]
188
+ * Arguments in custom types ([#143](https://github.com/pganalyze/pg_query/pull/143))
189
+ * Use "double precision" instead of "double" type name ([#139](https://github.com/pganalyze/pg_query/pull/139))
190
+ * Use explicit -z flag to support OpenBSD tar ([#134](https://github.com/pganalyze/pg_query/pull/134)) [@sirn]
110
191
  * Add Ruby 2.6 to Travis tests
111
192
  * Escape identifiers in more cases, if necessary
112
193
 
113
194
 
114
195
  ## 1.1.0 2018-10-04
115
196
 
116
- * Deparsing improvements by [@herwinw](https://github.com/herwinw)
117
- * Add NULLS FIRST/LAST to ORDER BY [#95](https://github.com/pganalyze/pg_query/pull/95)
118
- * VACUUM [#97](https://github.com/pganalyze/pg_query/pull/97)
119
- * UPDATE with multiple columns [#99](https://github.com/pganalyze/pg_query/pull/99)
120
- * DISTINCT ON [#101](https://github.com/pganalyze/pg_query/pull/101)
121
- * CREATE TABLE AS [#102](https://github.com/pganalyze/pg_query/pull/102)
197
+ * Deparsing improvements by [@herwinw]
198
+ * Add `NULLS FIRST`/`LAST` to `ORDER BY` [#95](https://github.com/pganalyze/pg_query/pull/95)
199
+ * `VACUUM` [#97](https://github.com/pganalyze/pg_query/pull/97)
200
+ * `UPDATE` with multiple columns [#99](https://github.com/pganalyze/pg_query/pull/99)
201
+ * `DISTINCT ON` [#101](https://github.com/pganalyze/pg_query/pull/101)
202
+ * `CREATE TABLE AS` [#102](https://github.com/pganalyze/pg_query/pull/102)
122
203
  * SQL value functions [#103](https://github.com/pganalyze/pg_query/pull/103)
123
- * LOCK [#105](https://github.com/pganalyze/pg_query/pull/105)
124
- * EXPLAIN [#107](https://github.com/pganalyze/pg_query/pull/107)
125
- * COPY [#108](https://github.com/pganalyze/pg_query/pull/108)
126
- * DO [#109](https://github.com/pganalyze/pg_query/pull/109)
127
- * Ignore pg_query.so in git checkout [#110](https://github.com/pganalyze/pg_query/pull/110) [@herwinw](https://github.com/herwinw)
128
- * Prefer __dir__ over File.dirname(__FILE__) [#110](https://github.com/pganalyze/pg_query/pull/104) [@herwinw](https://github.com/herwinw)
204
+ * `LOCK` [#105](https://github.com/pganalyze/pg_query/pull/105)
205
+ * `EXPLAIN` [#107](https://github.com/pganalyze/pg_query/pull/107)
206
+ * `COPY` [#108](https://github.com/pganalyze/pg_query/pull/108)
207
+ * `DO` [#109](https://github.com/pganalyze/pg_query/pull/109)
208
+ * Ignore pg_query.so in git checkout [#110](https://github.com/pganalyze/pg_query/pull/110) [@herwinw]
209
+ * Prefer `__dir__` over `File.dirname(__FILE__)` [#110](https://github.com/pganalyze/pg_query/pull/104) [@herwinw]
129
210
 
130
211
 
131
212
  ## 1.0.2 2018-04-11
132
213
 
133
214
  * Deparsing improvements
134
- * SELECT DISTINCT clause [#77](https://github.com/pganalyze/pg_query/pull/77) [@Papierkorb](https://github.com/Papierkorb)
135
- * "CASE expr WHEN ... END" clause [#78](https://github.com/pganalyze/pg_query/pull/78) [@Papierkorb](https://github.com/Papierkorb)
136
- * LEFT/RIGHT/FULL/NATURAL JOIN [#79](https://github.com/pganalyze/pg_query/pull/79) [@Papierkorb](https://github.com/Papierkorb)
137
- * SELECT that includes schema name [#80](https://github.com/pganalyze/pg_query/pull/80) [@jcsjcs](https://github.com/jcsjcs)
215
+ * `SELECT DISTINCT` clause [#77](https://github.com/pganalyze/pg_query/pull/77) [@Papierkorb]
216
+ * "`CASE expr WHEN ... END`" clause [#78](https://github.com/pganalyze/pg_query/pull/78) [@Papierkorb]
217
+ * `LEFT`/`RIGHT`/`FULL`/`NATURAL JOIN` [#79](https://github.com/pganalyze/pg_query/pull/79) [@Papierkorb]
218
+ * `SELECT` that includes schema name [#80](https://github.com/pganalyze/pg_query/pull/80) [@jcsjcs]
138
219
 
139
220
 
140
221
  ## 1.0.1 2018-02-02
141
222
 
142
- * Parse CTEs and nested selects in INSERT/UPDATE [#76](https://github.com/pganalyze/pg_query/pull/76) [@jcoleman](https://github.com/jcoleman)
143
- * Drop explicit json dependency [#74](https://github.com/pganalyze/pg_query/pull/74) [@yuki24](https://github.com/yuki24)
223
+ * Parse CTEs and nested selects in INSERT/UPDATE [#76](https://github.com/pganalyze/pg_query/pull/76) [@jcoleman]
224
+ * Drop explicit json dependency [#74](https://github.com/pganalyze/pg_query/pull/74) [@yuki24]
144
225
 
145
226
 
146
227
  ## 1.0.0 2017-10-31
@@ -155,7 +236,7 @@
155
236
  ## 0.13.5 2017-10-26
156
237
 
157
238
  * Update to libpg_query 9.5-1.7.1
158
- - Allow "$1 FROM $2" to be parsed (new with pg_stat_statements in Postgres 10)
239
+ - Allow "`$1 FROM $2`" to be parsed (new with pg_stat_statements in Postgres 10)
159
240
 
160
241
 
161
242
  ## 0.13.4 2017-10-20
@@ -166,12 +247,12 @@
166
247
 
167
248
  ## 0.13.3 2017-09-04
168
249
 
169
- * Fix table detection for SELECTs that have sub-SELECTs without FROM clause [#69](https://github.com/pganalyze/pg_query/issues/69)
250
+ * Fix table detection for SELECTs that have sub-SELECTs without `FROM` clause [#69](https://github.com/pganalyze/pg_query/issues/69)
170
251
 
171
252
 
172
253
  ## 0.13.2 2017-08-10
173
254
 
174
- * Support table detection in sub-SELECTs in JOINs [#68](https://github.com/pganalyze/pg_query/pull/65) [@seanmdick](https://github.com/seanmdick)
255
+ * Support table detection in sub-SELECTs in `JOIN`s [#68](https://github.com/pganalyze/pg_query/pull/65) [@seanmdick]
175
256
  * Legacy ".parsetree" helper: Fix "Between" and "In" operator does not have "AEXPR" [#66](https://github.com/pganalyze/pg_query/issues/66)
176
257
  * For new applications please use ".tree" method which uses the native structure
177
258
  returned from libpg_query which resembles Postgres node names more closely
@@ -179,13 +260,13 @@
179
260
 
180
261
  ## 0.13.1 2017-08-03
181
262
 
182
- * Fix regression in 0.13.1 that broke ".tables" logic for COPY statements that
263
+ * Fix regression in 0.13.1 that broke ".tables" logic for `COPY` statements that
183
264
  don't have a target table (i.e. are reading out data vs copying in)
184
265
 
185
266
 
186
267
  ## 0.13.0 2017-07-30
187
268
 
188
- * Introduce split between SELECT/DML/DDL for tables method [#65](https://github.com/pganalyze/pg_query/pull/65) [@chrisfrommann](https://github.com/chrisfrommann)
269
+ * Introduce split between SELECT/DML/DDL for tables method [#65](https://github.com/pganalyze/pg_query/pull/65) [@chrisfrommann]
189
270
  * Backwards compatible, use the new select_tables/dml_tables/ddl_tables to
190
271
  access the categorized table references
191
272
  * Update libpg_query to 9.5-1.6.2
@@ -213,14 +294,14 @@
213
294
 
214
295
  ## 0.11.5 2017-07-09
215
296
 
216
- * Deparse coldeflist [#64](https://github.com/pganalyze/pg_query/pull/64) [@jcsjcs](https://github.com/jcsjcs)
217
- * Use Integer class for checking integer instead of Fixnum [#62](https://github.com/pganalyze/pg_query/pull/62) [@makimoto](https://github.com/makimoto)
297
+ * Deparse coldeflist [#64](https://github.com/pganalyze/pg_query/pull/64) [@jcsjcs]
298
+ * Use Integer class for checking integer instead of Fixnum [#62](https://github.com/pganalyze/pg_query/pull/62) [@makimoto]
218
299
 
219
300
 
220
301
  ## 0.11.4 2017-01-18
221
302
 
222
- * Compatibility with Ruby 2.4 [#59](https://github.com/pganalyze/pg_query/pull/59) [@merqlove](https://github.com/merqlove)
223
- * Deparse varchar and numeric casts without arguments [#61](https://github.com/pganalyze/pg_query/pull/61) [@jcsjcs](https://github.com/jcsjcs)
303
+ * Compatibility with Ruby 2.4 [#59](https://github.com/pganalyze/pg_query/pull/59) [@merqlove]
304
+ * Deparse varchar and numeric casts without arguments [#61](https://github.com/pganalyze/pg_query/pull/61) [@jcsjcs]
224
305
 
225
306
 
226
307
  ## 0.11.3 2016-12-06
@@ -228,12 +309,12 @@
228
309
  * Update to newest libpg_query version (9.5-1.4.2)
229
310
  * Cut off fingerprints at 100 nodes deep to avoid excessive runtimes/memory
230
311
  * Fix warning on Linux due to missing asprintf include
231
- * Improved deparsing [@jcsjcs](https://github.com/jcsjcs)
312
+ * Improved deparsing [@jcsjcs]
232
313
  * Float [#54](https://github.com/pganalyze/pg_query/pull/54)
233
- * BETWEEN [#55](https://github.com/pganalyze/pg_query/pull/55)
234
- * NULLIF [#56](https://github.com/pganalyze/pg_query/pull/56)
235
- * SELECT NULL and BooleanTest [#57](https://github.com/pganalyze/pg_query/pull/57)
236
- * Fix build on BSD systems [#58](https://github.com/pganalyze/pg_query/pull/58) [@myfreeweb](https://github.com/myfreeweb)
314
+ * `BETWEEN` [#55](https://github.com/pganalyze/pg_query/pull/55)
315
+ * `NULLIF` [#56](https://github.com/pganalyze/pg_query/pull/56)
316
+ * `SELECT NULL` and BooleanTest [#57](https://github.com/pganalyze/pg_query/pull/57)
317
+ * Fix build on BSD systems [#58](https://github.com/pganalyze/pg_query/pull/58) [@myfreeweb]
237
318
 
238
319
 
239
320
  ## 0.11.2 2016-06-27
@@ -251,11 +332,11 @@
251
332
 
252
333
  ## 0.11.0 2016-06-22
253
334
 
254
- * Improved table name analysis (#tables method)
255
- * Don't include CTE names, make them accessible as #cte_names instead [#52](https://github.com/pganalyze/pg_query/issues/52)
335
+ * Improved table name analysis (`#tables` method)
336
+ * Don't include CTE names, make them accessible as `#cte_names` instead [#52](https://github.com/pganalyze/pg_query/issues/52)
256
337
  * Include table names in target list sub selects [#38](https://github.com/pganalyze/pg_query/issues/38)
257
- * Add support for ORDER/GROUP BY, HAVING, and booleans in WHERE [#53](https://github.com/pganalyze/pg_query/pull/53) [@jcoleman](https://github.com/jcoleman)
258
- * Fix parsing of DROP TYPE statements
338
+ * Add support for `ORDER`/`GROUP BY`, `HAVING`, and booleans in `WHERE` [#53](https://github.com/pganalyze/pg_query/pull/53) [@jcoleman]
339
+ * Fix parsing of `DROP TYPE` statements
259
340
 
260
341
 
261
342
  ## 0.10.0 2016-05-31
@@ -263,9 +344,9 @@
263
344
  * Based on PostgreSQL 9.5.3
264
345
  * Use LLVM extracted parser for significantly improved build times (via libpg_query)
265
346
  * Deparsing Improvements
266
- * SET statements [#48](https://github.com/pganalyze/pg_query/pull/48) [@Winslett](https://github.com/Winslett)
267
- * LIKE/NOT LIKE [#49](https://github.com/pganalyze/pg_query/pull/49) [@Winslett](https://github.com/Winslett)
268
- * CREATE FUNCTION improvements [#50](https://github.com/pganalyze/pg_query/pull/50) [@Winslett](https://github.com/Winslett)
347
+ * `SET` statements [#48](https://github.com/pganalyze/pg_query/pull/48) [@Winslett]
348
+ * `LIKE`/`NOT LIKE` [#49](https://github.com/pganalyze/pg_query/pull/49) [@Winslett]
349
+ * `CREATE FUNCTION` improvements [#50](https://github.com/pganalyze/pg_query/pull/50) [@Winslett]
269
350
 
270
351
 
271
352
  ## 0.9.2 2016-05-03
@@ -301,17 +382,17 @@
301
382
  ## 0.7.2 2015-12-20
302
383
 
303
384
  * Deparsing
304
- * Quote all column refs [#40](https://github.com/pganalyze/pg_query/pull/40) [@avinoamr](https://github.com/avinoamr)
305
- * Quote all range vars [#43](https://github.com/pganalyze/pg_query/pull/43) [@avinoamr](https://github.com/avinoamr)
306
- * Support for COUNT(DISTINCT ...) [#42](https://github.com/pganalyze/pg_query/pull/42) [@avinoamr](https://github.com/avinoamr)
385
+ * Quote all column refs [#40](https://github.com/pganalyze/pg_query/pull/40) [@avinoamr]
386
+ * Quote all range vars [#43](https://github.com/pganalyze/pg_query/pull/43) [@avinoamr]
387
+ * Support for `COUNT(DISTINCT ...)` [#42](https://github.com/pganalyze/pg_query/pull/42) [@avinoamr]
307
388
 
308
389
 
309
390
  ## 0.7.1 2015-11-17
310
391
 
311
392
  * Abstracted parser access into libpg_query [#24](https://github.com/pganalyze/pg_query/pull/35)
312
393
  * libpg_query
313
- * Use UTF-8 encoding for parsing [#4](https://github.com/lfittl/libpg_query/pull/4) [@zhm](https://github.com/zhm)
314
- * Add type to A_CONST nodes[#5](https://github.com/lfittl/libpg_query/pull/5) [@zhm](https://github.com/zhm)
394
+ * Use UTF-8 encoding for parsing [#4](https://github.com/lfittl/libpg_query/pull/4) [@zhm]
395
+ * Add type to A_CONST nodes[#5](https://github.com/lfittl/libpg_query/pull/5) [@zhm]
315
396
 
316
397
 
317
398
  ## 0.7.0 2015-10-17
@@ -320,25 +401,25 @@
320
401
  * Avoid bison/flex dependency to make deployment easier [#31](https://github.com/pganalyze/pg_query/issues/31)
321
402
  * Solve issues with deployments to Heroku [#32](https://github.com/pganalyze/pg_query/issues/32)
322
403
  * Deparsing
323
- * HAVING and FOR UPDATE [#36](https://github.com/pganalyze/pg_query/pull/36) [@JackDanger](https://github.com/JackDanger)
404
+ * `HAVING` and `FOR UPDATE` [#36](https://github.com/pganalyze/pg_query/pull/36) [@JackDanger]
324
405
 
325
406
 
326
407
  ## 0.6.4 2015-10-01
327
408
 
328
409
  * Deparsing
329
- * Constraints & Interval Types [#28](https://github.com/pganalyze/pg_query/pull/28) [@JackDanger](https://github.com/JackDanger)
330
- * Cross joins [#29](https://github.com/pganalyze/pg_query/pull/29) [@mme](https://github.com/mme)
331
- * ALTER TABLE [#30](https://github.com/pganalyze/pg_query/pull/30) [@JackDanger](https://github.com/JackDanger)
332
- * LIMIT and OFFSET [#33](https://github.com/pganalyze/pg_query/pull/33) [@jcsjcs](https://github.com/jcsjcs)
410
+ * Constraints & Interval Types [#28](https://github.com/pganalyze/pg_query/pull/28) [@JackDanger]
411
+ * Cross joins [#29](https://github.com/pganalyze/pg_query/pull/29) [@mme]
412
+ * `ALTER TABLE` [#30](https://github.com/pganalyze/pg_query/pull/30) [@JackDanger]
413
+ * `LIMIT and OFFSET` [#33](https://github.com/pganalyze/pg_query/pull/33) [@jcsjcs]
333
414
 
334
415
 
335
416
  ## 0.6.3 2015-08-20
336
417
 
337
418
  * Deparsing
338
- * COUNT(*) [@JackDanger](https://github.com/JackDanger)
339
- * Window clauses [Chris Martin](https://github.com/cmrtn)
340
- * CREATE TABLE/VIEW/FUNCTION [@JackDanger](https://github.com/JackDanger)
341
- * Return exact location for parser errors [@JackDanger](https://github.com/JackDanger)
419
+ * `COUNT(*)` [@JackDanger]
420
+ * Window clauses [Chris Martin]
421
+ * `CREATE TABLE`/`VIEW/FUNCTION` [@JackDanger]
422
+ * Return exact location for parser errors [@JackDanger]
342
423
 
343
424
 
344
425
  ## 0.6.2 2015-08-06
@@ -348,7 +429,7 @@
348
429
 
349
430
  ## 0.6.1 2015-08-06
350
431
 
351
- * Deparsing: Support WITH clauses in INSERT/UPDATE/DELETE [@JackDanger](https://github.com/JackDanger)
432
+ * Deparsing: Support `WITH` clauses in `INSERT`/`UPDATE`/`DELETE` [@JackDanger]
352
433
  * Make sure gemspec includes all necessary files
353
434
 
354
435
 
@@ -357,20 +438,20 @@
357
438
  * Deparsing (experimental)
358
439
  * Turns parse trees into SQL again
359
440
  * New truncate method to smartly truncate based on less important query parts
360
- * Thanks to [@mme](https://github.com/mme) & [@JackDanger](https://github.com/JackDanger) for their contributions
441
+ * Thanks to [@mme] & [@JackDanger] for their contributions
361
442
  * Restructure extension C code
362
443
  * Add table/filter columns support for CTEs
363
- * Extract views as tables from CREATE/REFRESH VIEW
444
+ * Extract views as tables from `CREATE`/`REFRESH VIEW`
364
445
  * Refactor code using generic treewalker
365
- * fingerprint: Normalize IN lists
446
+ * fingerprint: Normalize `IN` lists
366
447
  * param_refs: Fix length attribute in result
367
448
 
368
449
 
369
450
  ## 0.5.0 2015-03-26
370
451
 
371
452
  * Query fingerprinting
372
- * Filter columns (aka columns referenced in a query's WHERE clause)
373
- * Parameter references: Returns all $1/$2/etc like references in the query with their location
453
+ * Filter columns (aka columns referenced in a query's `WHERE` clause)
454
+ * Parameter references: Returns all `$1`/`$2`/etc like references in the query with their location
374
455
  * Remove dependency on active_support
375
456
 
376
457
 
@@ -387,3 +468,28 @@
387
468
 
388
469
 
389
470
  See git commit log for previous releases.
471
+
472
+ [libpg_query]: https://github.com/pganalyze/libpg_query
473
+ [@emin100]: https://github.com/emin100
474
+ [@akiellor]: https://github.com/akiellor
475
+ [@himanshu-pro]: https://github.com/himanshu-pro
476
+ [@himanshu]: https://github.com/himanshu
477
+ [@Tassosb]: https://github.com/Tassosb
478
+ [@herwinw]: https://github.com/herwinw
479
+ [@stanhu]: https://github.com/stanhu
480
+ [@Papierkorb]: https://github.com/Papierkorb
481
+ [@jcsjcs]: https://github.com/jcsjcs
482
+ [@jcoleman]: https://github.com/jcoleman
483
+ [@yuki24]: https://github.com/yuki24
484
+ [@seanmdick]: https://github.com/seanmdick
485
+ [@chrisfrommann]: https://github.com/chrisfrommann
486
+ [@makimoto]: https://github.com/makimoto
487
+ [@merqlove]: https://github.com/merqlove
488
+ [@myfreeweb]: https://github.com/myfreeweb
489
+ [@Winslett]: https://github.com/Winslett
490
+ [@avinoamr]: https://github.com/avinoamr
491
+ [@zhm]: https://github.com/zhm
492
+ [@mme]: https://github.com/mme
493
+ [@JackDanger]: https://github.com/JackDanger
494
+ [Chris Martin]: https://github.com/cmrtn
495
+ [@sirn]: https://github.com/sirn
data/README.md CHANGED
@@ -133,6 +133,18 @@ PgQuery.fingerprint("SELECT ?")
133
133
  => "50fde20626009aba"
134
134
  ```
135
135
 
136
+ ### Scanning a query into tokens
137
+
138
+ ```ruby
139
+ PgQuery.scan('SELECT 1 --comment')
140
+
141
+ => [<PgQuery::ScanResult: version: 130002, tokens: [
142
+ <PgQuery::ScanToken: start: 0, end: 6, token: :SELECT, keyword_kind: :RESERVED_KEYWORD>,
143
+ <PgQuery::ScanToken: start: 7, end: 8, token: :ICONST, keyword_kind: :NO_KEYWORD>,
144
+ <PgQuery::ScanToken: start: 9, end: 18, token: :SQL_COMMENT, keyword_kind: :NO_KEYWORD>]>,
145
+ []]
146
+ ```
147
+
136
148
  ## Differences from Upstream PostgreSQL
137
149
 
138
150
  This gem is based on [libpg_query](https://github.com/pganalyze/libpg_query),
data/Rakefile CHANGED
@@ -1,11 +1,12 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/clean'
2
3
  require 'rake/extensiontask'
3
4
  require 'rspec/core/rake_task'
4
5
  require 'rubocop/rake_task'
5
6
  require 'open-uri'
6
7
 
7
- LIB_PG_QUERY_TAG = '13-2.0.0'.freeze
8
- LIB_PG_QUERY_SHA256SUM = 'e5e6514b1ae0e1ab19a2441de3088988bf1b89778164f9c725c3d85c6903133e'.freeze
8
+ LIB_PG_QUERY_TAG = '13-2.1.0'.freeze
9
+ LIB_PG_QUERY_SHA256SUM = 'a01329ae5bac19b10b8ddf8012bd663a20f85f180d6d7b900c1a1ca8444d19a5'.freeze
9
10
 
10
11
  Rake::ExtensionTask.new 'pg_query' do |ext|
11
12
  ext.lib_dir = 'lib/pg_query'
@@ -20,11 +21,9 @@ task default: %i[spec lint]
20
21
  task test: :spec
21
22
  task lint: :rubocop
22
23
 
23
- task :clean do
24
- FileUtils.rm_rf File.join(__dir__, 'tmp/')
25
- FileUtils.rm_f Dir.glob(File.join(__dir__, 'ext/pg_query/*.o'))
26
- FileUtils.rm_f File.join(__dir__, 'lib/pg_query/pg_query.bundle')
27
- end
24
+ CLEAN.include 'tmp/**/*'
25
+ CLEAN.include 'ext/pg_query/*.o'
26
+ CLEAN.include 'lib/pg_query/pg_query.bundle'
28
27
 
29
28
  task :update_source do
30
29
  workdir = File.join(__dir__, 'tmp')
@@ -87,18 +86,4 @@ task :update_source do
87
86
  system("cp -a #{libdir}/testdata/* #{testfilesdir}")
88
87
  # Copy back the custom ext files
89
88
  system("cp -a #{extbakdir}/pg_query_ruby.{c,sym} #{extbakdir}/extconf.rb #{extdir}")
90
-
91
- # Generate JSON field name helper (workaround until https://github.com/protocolbuffers/protobuf/pull/8356 is merged)
92
- str = "module PgQuery\n INTERNAL_PROTO_FIELD_NAME_TO_JSON_NAME = {\n"
93
- cur_type = nil
94
- File.read(File.join(libdir, 'protobuf/pg_query.proto')).each_line do |line|
95
- if line[/^message (\w+)/]
96
- cur_type = $1
97
- next
98
- end
99
- next unless line[/(repeated )?\w+ (\w+) = \d+( \[json_name="(\w+)"\])?;/]
100
- str += format(" [%s, :%s] => '%s',\n", cur_type, $2, $4 || $2)
101
- end
102
- str += " }\nend\n"
103
- File.write(File.join(__dir__, 'lib/pg_query/json_field_names.rb'), str)
104
89
  end
@@ -3,10 +3,13 @@
3
3
  require 'digest'
4
4
  require 'mkmf'
5
5
  require 'open-uri'
6
+ require 'pathname'
6
7
 
7
- $objs = Dir.glob(File.join(__dir__, '*.c')).map { |f| f.gsub('.c', '.o') }
8
+ $objs = Dir.glob(File.join(__dir__, '*.c')).map { |f| Pathname.new(f).sub_ext('.o').to_s }
8
9
 
9
- $CFLAGS << " -I#{File.join(__dir__, 'include')} -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-protector -Wno-unused-function -Wno-unused-variable -g"
10
+ $CFLAGS << " -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-protector -Wno-unused-function -Wno-unused-variable -g"
11
+
12
+ $INCFLAGS = "-I#{File.join(__dir__, 'include')} " + $INCFLAGS
10
13
 
11
14
  SYMFILE = File.join(__dir__, 'pg_query_ruby.sym')
12
15
  if RUBY_PLATFORM =~ /darwin/
@@ -110,6 +110,18 @@
110
110
  #define pg_attribute_unused()
111
111
  #endif
112
112
 
113
+ /*
114
+ * Place this macro before functions that should be allowed to make misaligned
115
+ * accesses. Think twice before using it on non-x86-specific code!
116
+ * Testing can be done with "-fsanitize=alignment -fsanitize-trap=alignment"
117
+ * on clang, or "-fsanitize=alignment -fno-sanitize-recover=alignment" on gcc.
118
+ */
119
+ #if __clang_major__ >= 7 || __GNUC__ >= 8
120
+ #define pg_attribute_no_sanitize_alignment() __attribute__((no_sanitize("alignment")))
121
+ #else
122
+ #define pg_attribute_no_sanitize_alignment()
123
+ #endif
124
+
113
125
  /*
114
126
  * Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
115
127
  * used in assert-enabled builds, to avoid compiler warnings about unused