How to Avoid Excessive Sorts in Window Functions
Usually, this blog is 100% pro window functions and advocates using them at any occasion. But like any tool, window functions come at a price and we must carefully evaluate if that’s a price we’re...
View ArticleHow to Fetch Oracle DBMS_OUTPUT from JDBC
When working with Oracle stored procedures, it is not uncommon to have debug log information available from DBMS_OUTPUT commands. For instance, if we have a procedure like this: CREATE TABLE my_table...
View ArticleThe Cost of JDBC Server Roundtrips
Or: Move That Loop into the Server Already! This article will illustrate the significance of something that I always thought to be common sense, but I keep seeing people getting this (very) wrong in...
View ArticleCreating a Microsoft Excel Style Pivot Table With Grand Totals in SQL
This answer to a beautiful Stack Overflow question I’ve given recently needs further explanation in a blog post. When working with Microsoft Excel, we can create beautiful and also very insightful...
View ArticleDo not GRANT ALL PRIVILEGES to your Production Users
Thanks to the generous contributions of Timur Shaidullin, jOOQ 3.11 will now support GRANT and REVOKE statements through #6812. While implementing integration tests for these new features, I had...
View ArticleTop 5 Hidden jOOQ Features
jOOQ’s main value proposition is obvious: Type safe embedded SQL in Java. People who actively look for such a SQL builder will inevitably stumble upon jOOQ and love it, of course. But a lot of people...
View ArticleCalculating Tupper’s Self-Referential Formula With SQL
A really geeky way to start a Monday morning is to be nerd-sniped by the cool Fermat’s Library twitter account… Tupper's self-referential formula is a formula that visually represents itself when...
View ArticleMap Reducing a Set of Values Into a Dynamic SQL UNION Query
Sounds fancy, right? But it’s a really nice and reasonable approach to doing dynamic SQL with jOOQ. This blog post is inspired by a Stack Overflow question, where a user wanted to turn a set of values...
View ArticleTop 10 SQL Dialect Emulations Implemented in jOOQ
The SQL standard is a nice thing. But it’s a standard. And as such, while it may provide good guidelines on how to implement some SQL features, most dialects deviate from it in one way or another...
View ArticleA Completely Overhauled, Modularised jOOQ 3.11, Ready for Java 11
If you’ve been following the fast paced JDK 9+ projects, you may have noticed an exciting, first big change that has been made possible thanks to Java 9’s Jigsaw feature. In JDK 11, JEP 320 will ship,...
View ArticleWhy SQL Bind Variables are Important for Performance
A common problem with dynamic SQL is parsing performance in production. What makes matters worse is that many developers do not have access to production environments, so they are unaware of the...
View ArticleWhen Using Bind Variables is not Enough: Dynamic IN Lists
In a previous blog post, I wrote about why you should (almost) always default to using bind variables. There are some exceptions, which I will cover in another follow-up post, but by default, bind...
View ArticleThe Performance Difference Between SQL Row-by-row Updating, Batch Updating,...
Something that has been said many times, but needs constant repeating until every developer is aware of the importance of this is the performance difference between row-by-row updating and bulk...
View ArticleHow to Run a Bulk INSERT .. RETURNING Statement With Oracle and JDBC
When inserting records into SQL databases, we often want to fetch back generated IDs and possibly other trigger, sequence, or default generated values. Let’s assume we have the following table: -- DB2...
View ArticleSelecting all Columns Except One in PostgreSQL
Google’s BigQuery has a very interesting SQL language feature, which I’ve missed many times in other databases: select: SELECT [{ ALL | DISTINCT }] { [ expression. ]* [ EXCEPT ( column_name [, ...] ) ]...
View ArticleHow to Group By “Nothing” in SQL
The SQL standard knows a lesser known feature called GROUPING SETS. One particular side-effect of that feature is that we can group by “nothing” in SQL. E.g. when querying the Sakila database: SELECT...
View ArticleTruth First, or Why You Should Mostly Implement Database First Designs
In this much overdue article, I will explain why I think that in almost all cases, you should implement a “database first” design in your application’s data models, rather than a “Java first” design...
View ArticleUsing UNPIVOT to Traverse a Configuration Table’s Rows and Columns
Imagine you have a configuration table like the following: CREATE TABLE rule ( name VARCHAR2(50) NOT NULL PRIMARY KEY, enabled NUMBER(1) DEFAULT 1 NOT NULL CHECK (enabled IN (0,1)), priority NUMBER(10)...
View ArticlePostgreSQL 11’s Support for SQL Standard GROUPS and EXCLUDE Window Function...
Exciting discovery when playing around with PostgreSQL 11! New SQL standard window function clauses have been supported. If you want to play with this, you can do so very easily using docker: docker...
View ArticleHow SQL DISTINCT and ORDER BY are Related
One of the things that confuse SQL users all the time is how DISTINCT and ORDER BY are related in a SQL query. The Basics Running some queries against the Sakila database, most people quickly...
View Article