---
title: "The power of \\gexec"
publication: "Postgres Weekly"
issue: 464
published_at: "2022-07-20"
canonical_url: "https://postgresweekly.com/issues/464"
---

Plus a look at BRIN indexes, DISTINCT in Postgres 15, and a deep dive into materialized views. |        

#​464 — July 20, 2022 

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

Postgres Weekly 

[![\](https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60/v1658323472/dzjcs83w9wc1pcds23iz.jpg)](https://postgrespro.com/community/books/internals)  

[PostgreSQL 14 Internals: The Book](https://postgrespro.com/community/books/internals) — A book for those _“who will not settle for a black-box approach when working with a database”_ from one of our favorite authors of technical deep dives into Postgres features. Part one is available now as a [160+ page PDF.](https://edu.postgrespro.com/postgresql_internals-14_part1_en.pdf) 

Egor Rogov   

[`\gexec` in `psql`: A Postgres Power User Practice?](https://www.cybertec-postgresql.com/en/gexec-psql-postgresql-poweruser-practice/) — If you’ve used `eval` in languages like Python or JavaScript, `\gexec` provides a _similar_ mechanism in `psql` and opens some interesting ways to dynamically generate and run queries en masse. (If you like history, here’s [some background to the feature](https://www.postgresql.org/message-id/CADkLM=exRzVQu31kjaBPzpbu_rGUTtWDTNELNysg1ChEPSpDMQ@mail.gmail.com) from its original announcement on the pgsql-hackers list.) 

Julian Markwort   [![\](https://copm.s3.amazonaws.com/7c5bdb65.png)](https://tsdb.co/how-to-contribute-to-community) 

[First Insights from the State of PostgreSQL 2022 Report](https://tsdb.co/how-to-contribute-to-community) — The State of PostgreSQL survey was recently closed. While we keep digging into the results, read the first insights in our new blog post, and share your email to get notified when the full report will be published. 

Timescale sponsor   

**QUICK BITS:** 

- 🎧 The chaps behind the new Postgres podcast, [postgres.fm](https://postgres.fm/), explain [a little more about the project,](https://www.pgmustard.com/blog/postgres-fm-a-new-postgres-podcast) and have released a second episode about [▶️ managed Postgres services versus doing it yourself.](https://postgres.fm/episodes/managed-services-vs-diy)
- Amazon Aurora 'PostgreSQL-compatible edition' [now supports R6i instances.](https://aws.amazon.com/about-aws/whats-new/2022/07/amazon-aurora-postgresql-compatible-edition-r6i-instances/) Why does that matter? They scale [up to 1TB of RAM](https://aws.amazon.com/ec2/instance-types/r6i/) and 128 vCPUs, for starters.   

[Working with `DISTINCT` in Postgres 15](https://www.percona.com/blog/introducing-postgresql-15-working-with-distinct/) — Using `DISTINCT` with `SELECT` eliminates 'duplicate' rows from results by way of specified expressions. We’re still in [the beta phase](https://www.postgresql.org/about/news/postgresql-15-beta-2-released-2479/) of Postgres 15, but this post shows off how the performance of `SELECT DISTINCT` has been improved through parallelization. 

Robert Bernier   

[When Does BRIN Indexing Win?](https://www.crunchydata.com/blog/postgres-indexing-when-does-brin-win) — An easily digestible comparison of BRIN and BTree indexes and an explanation of when and why BRIN can make the most sense despite their relative simplicity (very large, insert-only tables, for instance). 

Paul Ramsey   

[How Postgres's Views and Materialized Views Work](https://www.timescale.com/blog/how-postgresql-views-and-materialized-views-work-and-how-they-influenced-timescaledb-continuous-aggregates/) — ..and, importantly to note, _“how they influenced TimescaleDB continuous aggregates.”_ Whether you use Timescale or not, this is a useful introduction to views that gracefully moves into why Timescale had to create extra mechanisms suited for time series use cases. 

David Kohn (Timescale)   

[Build Internal Tools 10x Faster with PostgreSQL](https://retool.com/integrations/postgresql?utm_source=sponsor&utm_medium=newsletter&utm_campaign=cooperpress) 

Retool sponsor   

▶[Postgres vs SQLite with Litestream](https://changelog.com/shipit/59) — As much as I love Postgres, SQLite is absolutely perfect for many use cases. [Litestream](https://litestream.io/) is a tool that lets you stream SQLite changes for storage elsewhere, opening up even more opportunities. Its creator, Ben Johnson, talks about it on this show and compares the overall approach to Postgres. 

Ship It Podcast podcast   

**RELEASES:** 

- [PostGIS 3.0.6](https://postgis.net/2022/07/20/postgis-3.0.6/) and [2.5.7](https://postgis.net/2022/07/19/postgis-2.5.7/) – both bug fix releases.
- [QuestDB 6.4.3](https://github.com/questdb/questdb) – Time series SQL database with Postgres wire protocol support.
- [pg_timetable 4.8](https://github.com/cybertec-postgresql/pg_timetable) – Advanced scheduling for Postgres.
- [pg_cron 1.4.2](https://github.com/citusdata/pg_cron) – Run periodic jobs.
- [dblab 0.15](https://github.com/danvergara/dblab) – TUI client for Postgres, MySQL and SQLite.    

**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! 

--- 

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|*)
