Introducing Crunchy Data Warehouse: A next-generation Postgres-native data warehouse. Crunchy Data Warehouse Learn more

Posts about Fun with SQL

  • 5 min read

    Crazy Idea to Postgres in the Browser

    Joey Mezzacappa

    We just launched our Postgres Playground . Running Postgres in the web browser was not exactly commonplace before, so naturally, people are wondering how it works. It actually started as a fun weekend experiment. Here's a screenshot I saved, just moments after recovering from the initial "whoa, it's working!" effect. The next morning, I shared this screenshot in our internal Slack channel for web frontend engineering. Our mental gears began to turn as we imagined what might (and might not) b...

    Read More
  • Rise of the Anti-Join

    Paul Ramsey

    Find me all the things in set "A" that are not in set "B". This is a pretty common query pattern, and it occurs in both non-spatial and spatial situations. As usual, there are multiple ways to express this query in SQL, but only a couple queries will result in the best possible performance. The non-spatial setup starts with two tables with the numbers 1 to 1,000,000 in them, then deletes two records from one of the tables. The spatial setup is a 2M record table of geographic names, and a 3K rec...

    Read More
  • 9 min read

    Quick and Easy Postgres Data Compare

    Brian Pace

    If you're checking archives or working with Postgres replication, data reconciliation can be a necessary task. Row counts can be one of the go to comparison methods but that does not show data mismatches. You could pull table data across the network and then compare each row and each field, but that can be a demand on resources. Today we'll walk through a simple solution for your Postgres toolbox - using Foreign Data Wrappers to connect and compare the two source datasets. With the foreign data...

    Read More
  • 8 min read

    Parquet and Postgres in the Data Lake

    Paul Ramsey

    A couple weeks ago, I came across a blog from Retool on their experience migrating a 4TB database. They put in place some good procedures and managed a successful migration, but the whole experience was complicated by the size of the database. The size of the database was the result of a couple of very large "logging" tables: an edit log and an audit log. The thing about log tables is, they don't change much. They are append-only by design. They are also queried fairly irregularly, and the qu...

    Read More
  • 13 min read

    How to Cheat at WORDLE with PostgreSQL

    Jean-Paul Argudo

    Wordle became very popular on the internet very quickly. It's a 5 letter word game to guess among all possible words in a given language. The French version is like the English one, except words aren't be written with the accents we have in French, like “é, è, ê, ë, à, ô,” etc. Words with the special character “œ” are written with 2 characters like “oe”. The French language has 7980 5-letter words. At least according to this website . Yes, I did copy/paste every 21 pages of the words in a...

    Read More
  • 5 min read

    Extracting and Substituting Text with Regular Expressions in PostgreSQL

    Paul Ramsey

    While supporting Crunchy Spatial and Crunchy Bridge clients, I’ve been thinking about how I usually clean messy data. I wanted to talk about regular expressions ( regex ) and Postgres. Regular expressions get a bad rap. They're impossible to read, they're inconsistently implemented in different platforms, they can be slow to execute. All of these things may be true, and yet: if you don't know regular expressions yet, you are missing a key skill for data manipulation that you will use throu...

    Read More
  • 6 min read

    Fun with SQL in Postgres: Finding Revenue Accrued Per Day

    Jonathan S. Katz

    I recently wrote an example of how you can project monthly recurring revenue ( MRR ) in Postgres . This is a helpful metric to understand how a subscription-based business is doing and can help inform all sorts of financial and operational decisions at the company. Since writing that example, my same friend running their SaaS business on Crunchy Bridge wanted to find out how much revenue they were accruing per day over the course of a month. When a new month started, the accrued revenue wou...

    Read More
  • 8 min read

    Projecting Monthly Revenue Run Rate in Postgres

    Jonathan S. Katz

    Monthly recurring revenue ( MRR ) and annual recurring revenue ( ARR ) are important metrics for a subscription-based business model. It allows for the business to project its available capital to make important decisions around expansion, hiring and more. In an on-demand subscription model, MRR can fluctuate on any given day. This is especially true in the cloud-services world, where people are constantly spinning up and down services. That's why it makes sense to try and capture what the su...

    Read More
  • 6 min read

    Devious SQL: Dynamic DDL in PostgreSQL

    David Christensen

    Supporting PostgreSQL DBAs is an important part of daily life here at Crunchy Data . I’ve recently run across a few use cases where utility queries based on the current state of the database are needed. A simple example could be where you have a table that is the target of logical replication and the column becomes out of sync with the sequence that generated the data. This would result in new rows having primary key conflicts. To correct this issue, you would need to set the sequence to gene...

    Read More
  • 8 min read

    Devious SQL: Message Queuing Using Native PostgreSQL

    David Christensen

    An interesting question came up on the #postgresql IRC channel about how to use native PostgreSQL features to handle queuing behavior. There are existing solutions for queuing, both in PostgreSQL, with the venerable pgq project, or dedicated message queues like RabbitMQ, Kafka, etc. I wanted to explore what could be done with native Postgres primitives and I thought this warranted an entry in my Devious SQL series . So what makes up a minimal queuing solution? Effectively, we need the followi...

    Read More