Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ include = [

[dependencies]
itertools = "0.10.3"
prost = "0.13.5"
prost = { git = "https://github.com/pganalyze/prost", branch = "recursion-limit-macro" }
serde = { version = "1.0.139", features = ["derive"] }
serde_json = "1.0.82"
thiserror = "1.0.31"

[build-dependencies]
bindgen = "0.66.1"
clippy = { version = "0.0.302", optional = true }
prost-build = "0.13.5"
prost-build = { git = "https://github.com/pganalyze/prost", branch = "recursion-limit-macro" }
fs_extra = "1.2.0"
cc = "1.0.83"
glob = "0.3.1"
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ let result = pg_query::parse(query).unwrap();
assert_eq!(result.truncate(32).unwrap(), "INSERT INTO x (...) VALUES (...)");
```

## Caveats

When parsing very complex queries you may run into a stack overflow. This can be worked around by using a thread with a custom stack size ([stdlib](https://doc.rust-lang.org/std/thread/index.html#stack-size), [tokio](https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html#method.thread_stack_size)), or using the stacker crate to resize the main thread's stack:

```rust
stacker::grow(20 * 1024 * 1024, || pg_query::parse(query))
```

However, a sufficiently complex query could still run into a stack overflow after you increase the stack size. With some work it may be possible to add an adapter API to the prost crate in order to dynamically increase the stack size as needed like [serde_stacker](https://crates.io/crates/serde_stacker) does (if anyone wants to take that on).

## Credits

Thanks to [Paul Mason](https://github.com/paupino) for his work on [pg_parse](https://github.com/paupino/pg_parse) that this crate is based on.
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
env::set_var("OUT_DIR", &src_dir);

let mut prost_build = prost_build::Config::new();
prost_build.recursion_limit("ParseResult", 1000);
prost_build.type_attribute(".", "#[derive(serde::Serialize)]");
prost_build.compile_protos(&[&out_protobuf_path.join("pg_query").with_extension("proto")], &[&out_protobuf_path])?;

Expand Down
2 changes: 1 addition & 1 deletion libpg_query
Submodule libpg_query updated 59 files
+26 −0 CHANGELOG.md
+4 −6 Makefile
+2 −2 README.md
+2 −2 pg_query.h
+11 −10 src/pg_query_summary.c
+10 −7 src/pg_query_summary_truncate.c
+1 −1 src/postgres/COPYRIGHT
+1 −1 src/postgres/include/access/amapi.h
+1 −1 src/postgres/include/access/slru.h
+11 −4 src/postgres/include/access/tableam.h
+1 −0 src/postgres/include/access/xlog.h
+2 −1 src/postgres/include/access/xlogdefs.h
+1 −1 src/postgres/include/commands/defrem.h
+18 −0 src/postgres/include/commands/trigger.h
+4 −0 src/postgres/include/executor/executor.h
+2 −1 src/postgres/include/miscadmin.h
+6 −8 src/postgres/include/nodes/execnodes.h
+10 −9 src/postgres/include/pg_config.h
+10 −2 src/postgres/include/port/atomics/generic-gcc.h
+9 −3 src/postgres/include/port/pg_iovec.h
+25 −9 src/postgres/include/replication/reorderbuffer.h
+2 −0 src/postgres/include/replication/slot.h
+1 −0 src/postgres/include/utils/elog.h
+1 −1 src/postgres/include/utils/guc.h
+0 −2 src/postgres/include/utils/guc_hooks.h
+5 −0 src/postgres/include/utils/pg_locale.h
+739 −732 src/postgres/src_backend_parser_gram.c
+11 −0 src/postgres/src_backend_utils_error_elog.c
+22 −7 src/postgres/src_backend_utils_mmgr_alignedalloc.c
+3 −3 src/postgres/src_backend_utils_mmgr_aset.c
+1 −1 src/postgres/src_backend_utils_mmgr_bump.c
+33 −8 test/framework/main.c
+6 −3 test/framework/main.h
+12 −12 test/parse_opts_tests.c
+36 −36 test/parse_tests.c
+30 −2 test/sql/postgres_regress/alter_table.sql
+14 −1 test/sql/postgres_regress/collate.icu.utf8.sql
+11 −0 test/sql/postgres_regress/constraints.sql
+1 −1 test/sql/postgres_regress/create_index.sql
+8 −0 test/sql/postgres_regress/create_table.sql
+62 −9 test/sql/postgres_regress/event_trigger.sql
+48 −0 test/sql/postgres_regress/foreign_key.sql
+32 −0 test/sql/postgres_regress/generated.sql
+4 −1 test/sql/postgres_regress/limit.sql
+49 −0 test/sql/postgres_regress/merge.sql
+24 −3 test/sql/postgres_regress/privileges.sql
+2 −0 test/sql/postgres_regress/psql.sql
+79 −0 test/sql/postgres_regress/publication.sql
+50 −1 test/sql/postgres_regress/rowsecurity.sql
+93 −0 test/sql/postgres_regress/stats_ext.sql
+23 −0 test/sql/postgres_regress/strings.sql
+26 −0 test/sql/postgres_regress/subselect.sql
+10 −0 test/sql/postgres_regress/triggers.sql
+14 −0 test/sql/postgres_regress/with.sql
+2 −0 test/sql/postgres_regress/xml.sql
+1 −1 test/summary.c
+11 −0 test/summary_tests.c
+2 −0 test/summary_tests_list.c
+1 −1 test/summary_truncate.c
Loading