Topic

SQL

Discover SQL best practices covering query optimization, database design, normalization, and relational database management. Our digest aggregates ACID compliance, transaction patterns, and distributed query from developer communities.

What this topic tracks

  • Database releases and ecosystem updates
  • Query, indexing, and modeling practices
  • Operational lessons from production systems

SQL · 85 stories

Recent stories

Each story's summary, with the places it was discussed.

Summaries are written by AI from the linked sources. Open the source for full context.

20 stories

SQL patterns I use to catch transaction fraud

analytics.fixelsmith.com · 12 May

Data Science · Database · SQL

This guide outlines six SQL patterns for detecting transaction fraud, including velocity checks, geographic impossibility, amount anomalies, merchant behavior analysis, off-hours tracking, and the use of window functions for rapid iteration.

These techniques help identify suspicious activity in financial or benefit-related datasets, emphasizing that SQL remains the most effective tool for practical, scalable fraud detection.

Neki

planetscale.com · 10 Sept

Database · Distributed Systems · SQL

PlanetScale has launched Neki in platform preview, a sharded Postgres service that scales across machines while retaining real Postgres on every shard.

Its router preserves standard drivers and ORMs; built-in topology, pooling, failover, online schema changes, upgrades, imports, and resharding simplify operations. It supports unsharded deployment, but preview users should avoid production workloads.

I don't trust ON DELETE CASCADE

planetscale.com · 21 Oct

Backend · Database · Performance · PostgreSQL · SQL

ON DELETE CASCADE can turn simple deletions into outages and replication failures as foreign-key trees grow.

A cascading delete removes matching rows in one transaction, generating dead tuples, index updates, and WAL while holding locks; migrations may queue writes, unindexed keys can trigger scans, and logical replication can leave orphans or fail without replica identity. Soft deletes avoid this by marking one row, then reaping descendants in small background batches, keeping transactions short and bounded.

Sequences and other volatiles in Neki

planetscale.com · 14 Oct

Backend · Database · Distributed Systems · PostgreSQL · SQL

Neki implements PostgreSQL sequences in its sharded query planner by making sequence operations router-only and coordinating allocation through an authoritative shard.

Because nextval() is volatile, Neki must evaluate it once per output row, even when rows arrive from multiple shards, while stable expressions such as now() are evaluated once per statement. Shard-local joins and immutable expressions can still be pushed down. For UPDATE, Neki locks and streams row IDs to the router, then sends parameterized per-row updates with globally unique sequence values.

Why DuckDB is my first choice for data processing

robinlinacre.com · 23 Aug

Database · Python · SQL

DuckDB is an open source in-process SQL engine optimized for analytical queries (OLAP), offering performance up to 1,000 times faster than traditional transactional databases like Postgres for large datasets.

Its lightweight nature as a single binary makes it easy to install and integrate into Python environments via pip. DuckDB simplifies data engineering by allowing direct querying of various file formats like parquet, csv, and json, even from remote sources like S3. Key advantages include ergonomic SQL extensions such as EXCLUDE and COLUMNS, ACID compliance for bulk operations, and high-performance custom UDFs. Its zero-startup time makes it ideal for CI/CD pipelines, significantly improving the developer experience compared to heavier alternatives like Spark.

ChatGPT Work Tool and Skill Reference

codex-tool-reference.simonw.chatgpt.site · 31 Aug

Software Architecture · SQL · UI

Defines a governed workflow for Data Analytics artifacts: validate complete manifests and bounded snapshots before rendering, use native MCP or Work Mode delivery paths appropriately, preserve provenance, enforce chart and table schemas, provide exploration-ready data, and fall back to static outputs only when necessary.

It also specifies titles, subtitles, metadata, sorting, and sharing requirements.

Learn SQL Once, Use It for 30 Years

fagnerbrack.com · 31 May

Database · PostgreSQL · SQL

SQL is a uniquely durable programming language based on relational algebra, allowing queries written decades ago to function in modern systems like PostgreSQL.

Unlike fast-evolving frameworks such as JavaScript, SQL offers career longevity through its mathematical foundation. While it has legacy flaws, mastering core SQL remains the most valuable long-term investment for software developers.

duckdb/ducklake

github.com · 7 Oct

Big Data · Database · SQL

DuckLake is an open lakehouse format and DuckDB extension that separates metadata from data: a catalog database stores metadata, while Parquet files store table data.

It lets DuckDB attach DuckLake databases and use standard SQL to create, query, update, and evolve tables. Built-in capabilities include time travel and change data feeds, distinguishing it from a simple Parquet-based storage layer by providing integrated cataloging and versioned data operations.

Sqldef: Idempotent schema management tool for MySQL, PostgreSQL, SQLite

sqldef.github.io · 1 Feb

Database · PostgreSQL · SQL

sqldef is an innovative command-line interface tool designed to streamline database schema management by performing diff operations between two SQL schemas.

Unlike traditional migration tools that require managing stateful migration files, sqldef allows developers to update their relational database management systems by comparing a desired SQL schema with the current live state. The tool provides robust support for a wide range of popular databases, including MySQL, MariaDB, TiDB, PostgreSQL, SQL Server, and SQLite3. By generating the necessary DDL statements to reconcile differences, it simplifies the Continuous Integration and deployment lifecycle for backend developers. Additionally, an online demo environment utilizes a WebAssembly build of sqldef, enabling users to experiment with schema comparisons and DDL generation directly within a web browser without local installation.

What Is a Database Transaction?

planetscale.com · 22 Feb

Database · PostgreSQL · SQL

This article explores database transactions, explaining atomicity through BEGIN, COMMIT, and ROLLBACK.

It compares Postgres's multi-versioning (MVCC) and VACUUM processes against MySQL's undo logs. Additionally, it details isolation levels—Serializable, Repeatable Read, Read Committed, and Read Uncommitted—and how both systems handle concurrent writes using locking or optimistic serialization.

Looking Forward to Postgres 19: Query Hints

pgedge.com · 5 Jun

Database · PostgreSQL · SQL

Postgres 19 introduces 'plan advice' through two new modules, pg_plan_advice and pg_stash_advice, effectively adding query hints.

Unlike traditional implementations, these keep advice outside SQL, guide rather than replace the planner, and provide granular feedback. This design addresses long-term community concerns regarding maintenance and the importance of allowing DBAs a graceful escape hatch for problematic queries.

What Changes When You Upgrade from PostgreSQL 18 to 19

rishigoomar.com · 26 Nov

Backend · Database · Performance · PostgreSQL · SQL

PostgreSQL 19 brings measurable day-to-day improvements over 18: foreign-key batch inserts were 41.1% faster, and eligible NOT IN queries were 24.5% faster in tests.

Native REPACK CONCURRENTLY reclaims space online, pg_plan_advice exposes and tests planner choices, and ON CONFLICT DO SELECT returns existing rows in one round-trip. WAIT FOR LSN helps replicas catch up before reads. Upgrade checks include extensions, removed io_workers, disabled-by-default JIT, lock settings, and logical-replication sequence synchronization.

Tin: full-text search for Postgres

planetscale.com · 16 Sept

Database · Performance · SQL

TIN, a GA full-text search extension for Postgres, supports Boolean, phrase, span, fuzzy, wildcard, regex, folding, COUNT(*) and BM25 ranking while handling updates, MVCC, replication, backups, and joins.

Benchmarks show at least 8× higher throughput than alternatives. Its speed comes from using Postgres ctid identifiers, vectorized bitmaps, and efficient segment merging.

Can GROUP BY still be optimized after all these years?

pivotlake.io · 3 Nov

Algorithms · Big Data · Database · Performance · SQL

Pivot found a significant optimization for top-K GROUP BY queries, such as finding the 10 items with the most orders.

Conventional analytical databases aggregate rows into private per-thread hash tables, merge partition results, and concatenate them, even though only a few partitions may affect the final answer; with 4,096 partitions, at least 4,086 are irrelevant to a top-10 result. The proposed approach tracks partition-level aggregate information, potentially using Bloom filters or counters, to prune unnecessary work.

Postgres transactions are a distributed systems superpower

dbos.dev · 2 Jul

Database · PostgreSQL · SQL

Co-locating workflow state within the same Postgres database as application data enables atomic updates.

By bundling database changes and workflow checkpoints into single transactions, developers can guarantee exactly-once execution and simplify complex patterns like idempotency and outbox messaging, ultimately enhancing reliability and reducing the overhead typically found in distributed workflow systems.

Looking Ahead to Postgres 19

snowflake.com · 30 Jun

Database · PostgreSQL · SQL

Postgres 19, currently in beta, introduces significant improvements including native REPACK CONCURRENTLY, partition merging and splitting, and enhanced logical replication.

New features like SQL property graph queries and SQL syntax upgrades improve developer productivity, while autovacuum and planner enhancements boost database maintenance and performance. These updates strengthen Postgres as a versatile and manageable production-ready system.

Planet Labs' open satellite feed

tech.marksblogg.com · 9 Sept

Database · SQL · Open Source

Planet Labs operates multiple satellite constellations, collecting daily global land imagery, including Pelican’s 426-band hyperspectral data.

Its open Disaster Data feed provides pre- and post-event imagery with STAC metadata. Using DuckDB, GDAL, QGIS, Parquet and GeoTIFF workflows, the analysis catalogs, mosaics, compresses and evaluates disaster imagery, including 24 Nepal flood scenes published as quickly as 1.4 hours after capture.

We gave terabytes of CI logs to an LLM

mendral.com · 27 Feb

Artificial Intelligence · Database · SQL

Mendral (YC W26) utilizes a SQL interface and ClickHouse to empower AI agents to investigate flaky CI tests.

By denormalizing 48 metadata columns per log line, they achieve 35:1 compression and millisecond query latency. This architecture allows agents to autonomously scan billions of log lines, identifying root causes across months of history in seconds.

Two Bits Are Better Than One: making bloom filters 2x more accurate

floedb.ai · 16 Feb

Algorithms · Database · SQL

Floe explains using bloom filters, probabilistic data structures that efficiently speed up SQL queries by filtering non-matching rows before decompression.

By implementing a fixed-size 256KB filter with two bits stored in a single uint32, they reduced false positive rates by 2x (11.7% to 5.7%) with negligible performance costs, significantly optimizing database join operations.

The only scalable delete in Postgres is DROP TABLE

planetscale.com · 11 Jun

Database · PostgreSQL · SQL

In PostgreSQL, row-level DELETE operations create bloat by adding dead tuples and increasing vacuuming demand.

They do not immediately reclaim disk space. For large-scale data cleanup, scaling strategies favor DROP TABLE or TRUNCATE, as they efficiently release space at the OS level. Partitioning is recommended to transform bulk deletions into manageable, recurring table maintenance tasks.

Where it came fromHacker NewsPlanetScaleCreate a Snapbyte.dev digest and choose SQL as one of your topics.Build your digest