Nested Transactions in jOOQ
Since jOOQ 3.4, we have an API that simplifies transactional logic on top of JDBC in jOOQ, and starting from jOOQ 3.17 and #13502, an equivalent API will also be made available on top of R2DBC, for...
View ArticleHow to Typesafely Map a Nested SQL Collection into a Nested Java Map with jOOQ
A really cool, recent question on Stack Overflow was about how to map a nested collection into a Java Map with jOOQ. In the past, I've blogged about the powerful MULTISET operator many times, which...
View ArticleSetting the JDBC Statement.setFetchSize() to 1 for Single Row Queries
An interesting hint by Vladimir Sitnikov has made me think about a new benchmark for jOOQ: https://twitter.com/lukaseder/status/1407662449331949568 The benchmark should check whether single row queries...
View ArticleThe Many Different Ways to Fetch Data in jOOQ
The jOOQ API is all about convenience, and as such, an important operation (the most important one?) like fetch() must come with convenience, too. The default way to fetch data is this:...
View ArticleChanging SELECT .. FROM Into FROM .. SELECT Does Not “Fix” SQL
Every now and then, I see folks lament the SQL syntax's peculiar disconnect between the lexical order of operations (SELECT .. FROM) the logical order of operations (FROM .. SELECT) Most recently here...
View ArticleThe Performance of Various To-Many Nesting Algorithms
It's been a while since jOOQ 3.15 has been released with its revolutionary standard SQL MULTISET emulation feature. A thing that has been long overdue and which I promised on twitter a few times is to...
View ArticleHow to Filter a SQL Nested Collection by a Value
I stumbled upon a very interesting question on Stack Overflow about how to use jOOQ's MULTISET operator to nest a collection, and then filter the result by whether that nested collection contains a...
View ArticleCreate Dynamic Views with jOOQ 3.17’s new Virtual Client Side Computed Columns
One of jOOQ 3.17's coolest new features are client side computed columns. jOOQ 3.16 already added support for server side computed columns, which many of you appreciate for various reasons. What's a...
View ArticleUsing H2 as a Test Database Product with jOOQ
The H2 database is an immensely popular in-memory database product mostly used by Java developers for testing. If you check out the DB-Engines ranking, it ranks 50th, which is quite impressive, as this...
View ArticleA Condition is a Field
Starting with jOOQ 3.17, the Condition type extends the Field<Boolean> type. Because, that's what the SQL standard thinks it is, in sorts: <boolean value expression> ::= <predicate>...
View ArticleHow to Plot an ASCII Bar Chart with SQL
No need for expensive Tableau subscriptions. Ditch Microsoft Excel. Just use native PostgreSQL to quickly visualise your data! Here's an idea I had for a while. As you may know, jOOQ can produce fancy...
View ArticleLATERAL is Your Friend to Create Local Column Variables in SQL
The standard SQL WITH clause has been tremendously helpful in structuring SQL queries. Instead of nesting everything in unreadable derived tables like this: SELECT actor_id, name, COUNT(*) FROM (...
View ArticleWhen to Use jOOQ and When to Use Native SQL
A frequently encountered doubt people have when using jOOQ is to decide when a "complex" query should be written using jOOQ API vs. when it should be implemented using native SQL. The jOOQ manual is...
View ArticleEmulating Window Functions in MySQL 5.7
One of MySQL 8's biggest improvements is the support of window functions. As I always said in conferences, there's SQL before window functions and SQL after window functions. Once you start using them,...
View ArticleThe Performance Impact of SQL’s FILTER Clause
I've found an interesting question on Twitter, recently. Is there any performance impact of using FILTER in SQL (PostgreSQL, specifically), or is it just syntax sugar for a CASE expression in an...
View ArticleHow to Write a Derived Table in jOOQ
One of the more frequent questions about jOOQ is how to write a derived table (or a CTE). The jOOQ manual shows a simple example of a derived table: In SQL: SELECT nested.* FROM ( SELECT AUTHOR_ID,...
View ArticleHow to Turn a List of Flat Elements into a Hierarchy in Java, SQL, or jOOQ
Occasionally, you want to write a SQL query and fetch a hierarchy of data, whose flat representation may look like this: SELECT id, parent_id, label FROM t_directory; The result might be: |id...
View ArticleMaven Coordinates of the most popular JDBC Drivers
Do you need to add a JDBC driver to your application, and don't know its Maven coordinates? This blog post lists the most popular drivers from the jOOQ integration tests. Look up the latest versions...
View ArticleWorkaround for MySQL’s “can’t specify target table for update in FROM clause”...
In MySQL, you cannot do this: create table t (i int primary key, j int); insert into t values (1, 1); update t set j = (select max(j) from t) + 1; The UPDATE statement will raise an error as follows:...
View ArticlejOOQ 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...
View Article