---
title: "A library for parsing and deparsing Postgres queries"
publication: "Postgres Weekly"
issue: 398
published_at: "2021-03-24"
canonical_url: "https://postgresweekly.com/issues/398"
---

Plus three things to remember about indexes. |        

#398 — March 24, 2021 

[Web Version](https://postgresweekly.com/issues/398)   

Postgres Weekly 

[![\](https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60/lwkvswdsvysynlayygvj.jpg)](https://pganalyze.com/blog/pg-query-2-0-postgres-query-parser)   

[pg_query 2.0: The Easiest Way to Parse Postgres Queries](https://pganalyze.com/blog/pg-query-2-0-postgres-query-parser) — `pg_query` is a standalone library for parsing Postgres SQL queries - version 2 adds support for Postgres 13 and includes a _deparser_ so that manipulated parse trees can be turned _back_ into SQL.. big opportunities there. It’s a C library but available in [a Ruby library](https://github.com/pganalyze/pg_query) as well as [Python](https://pypi.org/project/pglast/) and [Node.js](https://www.npmjs.com/package/pgsql-parser) bindings. 

Lukas Fittl   [![\](https://copm.s3.amazonaws.com/ab33e2ad.jpg)](https://tsdb.co/postgres-2021-survey) 

[🐘The State of PostgreSQL 2021 Survey Is Now Open ✨](https://tsdb.co/postgres-2021-survey) — Whether you’re new to Postgres or a decades-long contributor, we’d love to hear from you. Just like with last year's survey, we'll publish key findings and make anonymized source data available for everyone in the Postgres community 👉 [Start the survey](https://tsdb.co/postgres-2021-survey). 

Timescale sponsor   

[Getting Started with `EXPLAIN` (`ANALYZE`)](https://blog.crunchydata.com/blog/get-started-with-explain-analyze) — Prefixing a query with `EXPLAIN` lets you see how Postgres’s execution planner has interpreted the query and how it plans to execute it. The `ANALYZE` option goes a bit further and actually runs the query supplementing the more general information. 

Kat Batuigas   

[Sharding Postgres on a Single Citus Node: How, Why and When](https://www.citusdata.com/blog/2021/03/20/sharding-postgres-on-a-single-citus-node/) — Citus is designed for horizontally scaling Postgres across lots of nodes but what if you just have _one_? You can still play and test. 

Onder Kalaci   

[Three Easy Things To Remember About Postgres Indexes](https://blog.crunchydata.com/blog/three-easy-things-to-remember-about-postgres-indexes) — From 2020 but we missed it at the time. 

Kat Batuigas   

[Don't Let Collation Versions Corrupt Your Postgres Indexes](https://techcommunity.microsoft.com/t5/azure-database-for-postgresql/don-t-let-collation-versions-corrupt-your-postgresql-indexes/ba-p/1978394) — _“Collations and dependencies are nerdy topics — a bit like leap seconds and time zones: you know, the kinds of obscure things you don’t normally have to worry about until something is broken.”_ 

Thomas Munro   

[Writing a Postgres SQL Pretty Printer in Rust: Part 1](https://blog.urth.org/2021/03/14/writing-a-postgres-sql-pretty-printer-in-rust-part-1/) — The first in a planned series of blog posts about the development of [`pg-pretty`](https://github.com/houseabsolute/pg-pretty), a Rust-based SQL pretty printer work-in-progress. 

Dave Rolsky   

[Fauna: All the Goodness of Postgres, Without Operational Bottlenecks](https://fauna.com/postgres?utm_source=PostgresWeekly&utm_medium=Newsletter&utm_campaign=CooperPress_Newsletters_2021) — Fauna combines the safety of Postgres with schema flexibility, modern capabilities and limitless scale. [Learn more](https://fauna.com/postgres?utm_source=PostgresWeekly&utm_medium=Newsletter&utm_campaign=CooperPress_Newsletters_2021)... 

Fauna sponsor   

[Managing Multiple Postgres Instances on FreeBSD](https://fluca1978.github.io/2021/03/22/PostgreSQLFreeBSDMultiInstance.html) — By using different profiles with `rc.conf`. 

Luca Ferrari   

[How to Check and Resolve Bloat in Postgres](https://www.highgo.ca/2021/03/20/how-to-check-and-resolve-bloat-in-postgresql/) — A perennial topic. 

Asif Rehman   

[Setting Up SSL Authentication for Postgres](https://www.cybertec-postgresql.com/en/setting-up-ssl-authentication-for-postgresql/) 

Hans-Jürgen Schönig   

[Ltree Hierarchy: Organize ActiveRecord Models Into a Tree using Postgres's Ltree Type](https://github.com/cfabianski/ltree_hierarchy) — This library is for Rubyists, but more generally you can learn about this technique in [_Saving a Tree in Postgres Using LTREE_](http://patshaughnessy.net/2017/12/13/saving-a-tree-in-postgres-using-ltree) from 2017. 

Cédric Fabianski    

**Got a new email?** You can [change your address here](https://postgresweekly.com/edit_subscription/*|UID|*). 

--- 

**Bored of us?** [Click here to stop getting Postgres Weekly](https://postgresweekly.com/leave/*|UID|*). 

--- 

**Got a link for us?** Reply and tell us. We can't include everything but we'll look at anything you send. Thanks! 

--- 

**Want more?** You might like [DB Weekly](https://dbweekly.com/?utm_source=pg&utm_medium=email&utm_campaign=footer-promo), our more general database newsletter covering data storage trends, new database types, and more. 

--- 

Published by Cooper Press Ltd.
Fairfield Enterprise Centre, Louth, LN11 0LS, United Kingdom 

Postgres, PostgreSQL and the Slonik Logo are trademarks or registered trademarks of the PostgreSQL Community Association of Canada. 

[Stop getting this newsletter.](https://postgresweekly.com/leave/*|UID|*)
