Consider using JSON arrays instead of JSON objects for serialisation

When implementing the awesome MULTISET operator in jOOQ, its implementation mostly relied on SQL/JSON support of various RDBMS. In short, while standard SQL supports nested collections via ARRAY or MULTISET operators like this: SELECT f.title, MULTISET( SELECT a.first_name, a.last_name FROM actor AS a JOIN film_actor AS fa ON a.actor_id = fa.actor_id WHERE fa.film_id = f.film_id … Continue reading Consider using JSON arrays instead of JSON objects for serialisation

When SQL Meets Lambda Expressions

ARRAY types are a part of the ISO/IEC 9075 SQL standard. The standard specifies how to: Construct arrays Nest data into arrays (e.g. by means of aggregation or subqueries) Unnest data from arrays into tables But it is very unopinionated when it comes to function support. The ISO/IEC 9075-2:2023(E) 6.47 <array value expression> specifies concatenation … Continue reading When SQL Meets Lambda Expressions

Think About SQL MERGE in Terms of a RIGHT JOIN

RIGHT JOIN is an esoteric feature in the SQL language, and hardly ever seen in the real world, because almost every RIGHT JOIN can just be expressed as an equivalent LEFT JOIN. The following two statements are equivalent: -- Popular SELECT c.first_name, c.last_name, p.amount FROM customer AS c LEFT JOIN payment AS p ON c.customer_id … Continue reading Think About SQL MERGE in Terms of a RIGHT JOIN

Resisting the Urge to Document Everything Everywhere

Every product manager knows this situation: A user works with feature X1. They find a limitation / bug / quirk and want to work around it. The perfect workaround or alternative is feature X2, but without knowing that X2 exists, the user doesn't find it and spends a lot of time looking for it. The … Continue reading Resisting the Urge to Document Everything Everywhere

jOOQ 3.20 released with ClickHouse, Databricks, and much more DuckDB support, new modules, Oracle type hierarchies, more spatial support, decfloat and synonym support, hidden columns, Scala 3, Kotlin 2, and much more

New dialects: jOOQ 3.20 ships with 2 new experimental dialects: ClickHouse in all editions, including the jOOQ Open Source Edition Databricks in the jOOQ Enterprise Edition ClickHouse is a fast-moving SQL dialect with a historic vendor-specific syntax that is gradually migrated to a more standards compliant alternative, which is why our support is still experimental. … Continue reading jOOQ 3.20 released with ClickHouse, Databricks, and much more DuckDB support, new modules, Oracle type hierarchies, more spatial support, decfloat and synonym support, hidden columns, Scala 3, Kotlin 2, and much more

Emulating SQL FILTER with Oracle JSON Aggregate Functions

A cool standard SQL:2003 feature is the aggregate FILTER clause, which is supported natively by at least these RDBMS: ClickHouse CockroachDB DuckDB Firebird H2 HSQLDB PostgreSQL SQLite Trino YugabyteDB The following aggregate function computes the number of rows per group which satifsy the FILTER clause: SELECT COUNT(*) FILTER (WHERE BOOK.TITLE LIKE 'A%'), COUNT(*) FILTER (WHERE … Continue reading Emulating SQL FILTER with Oracle JSON Aggregate Functions

Getting Top 1 Values Per Group in Oracle

I've blogged about generic ways of getting top 1 or top n per category queries before on this blog. An Oracle specific version in that post used the arcane KEEP syntax: SELECT max(actor_id) KEEP (DENSE_RANK FIRST ORDER BY c DESC, actor_id), max(first_name) KEEP (DENSE_RANK FIRST ORDER BY c DESC, actor_id), max(last_name) KEEP (DENSE_RANK FIRST ORDER … Continue reading Getting Top 1 Values Per Group in Oracle

An Efficient Way to Check for Existence of Multiple Values in SQL

In a previous blog post, we've advertised the use of SQL EXISTS rather than COUNT(*) to check for existence of a value in SQL. I.e. to check if in the Sakila database, actors called WAHLBERG have played in any films, instead of: SELECT count(*) FROM actor a JOIN film_actor fa USING (actor_id) WHERE a.last_name = … Continue reading An Efficient Way to Check for Existence of Multiple Values in SQL

A Hidden Benefit of Implicit Joins: Join Elimination

One of jOOQ's key features so far has always been to render pretty much exactly the SQL that users expect, without any surprises - unless some emulation is required to make a query work, of course. This means that while join elimination is a powerful feature of many RDBMS, it isn't part of jOOQ's feature … Continue reading A Hidden Benefit of Implicit Joins: Join Elimination

jOOQ 3.19’s new Explicit and Implicit to-many path joins

jOOQ 3.19 finally delivers on a set of features that will greatly simplify your queries further, after jOOQ 3.11 introduced implicit to-one joins: Explicit path joins To-many path joins Implicit join path correlation What are these features? Many ORMs (e.g. JPA, Doctrine, jOOQ 3.11 and others) support "path joins" (they may have different names for … Continue reading jOOQ 3.19’s new Explicit and Implicit to-many path joins