The SQL standard knows an interesting feature where you can project any functional dependencies of a primary (or unique) key that is listed in the GROUP BY clause without having to add that functional dependency to the GROUP BY clause explicitly. What does this mean? Consider this simple schema: CREATE TABLE author ( id INT … Continue reading Functional Dependencies in SQL GROUP BY
Tag: sql standard
Using IGNORE NULLS With SQL Window Functions to Fill Gaps
I found a very interesting SQL question on Twitter recently: https://twitter.com/vikkiarul/status/1120669222672261120 Rephrasing the question: We have a set of sparse data points: +------------+-------+ | VALUE_DATE | VALUE | +------------+-------+ | 2019-01-01 | 100 | | 2019-01-02 | 120 | | 2019-01-05 | 125 | | 2019-01-06 | 128 | | 2019-01-10 | 130 | +------------+-------+ … Continue reading Using IGNORE NULLS With SQL Window Functions to Fill Gaps
Oracle’s OFFSET .. FETCH Can be Slower than Classic ROWNUM Filtering
One of Oracle 12c's coolest features was the introduction of the SQL standard OFFSET .. FETCH clause, as we can now write things like: SELECT * FROM film ORDER BY film_id FETCH FIRST 1 ROW ONLY This is querying the Sakila database. Most other databases had this clause (or a non-standard version of it) for … Continue reading Oracle’s OFFSET .. FETCH Can be Slower than Classic ROWNUM Filtering
Top 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 (sometimes drastically, cheers, MySQL). But that doesn't have to be a bad thing. Innovation is not driven by … Continue reading Top 10 SQL Dialect Emulations Implemented in jOOQ
jOOQ Tuesdays: Glenn Paulley Gives Insight into SQL’s History
Welcome to the jOOQ Tuesdays series. In this series, we’ll publish an article on the third Tuesday every other month where we interview someone we find exciting in our industry from a jOOQ perspective. This includes people who work with SQL, Java, Open Source, and a variety of other related topics. I'm very excited to … Continue reading jOOQ Tuesdays: Glenn Paulley Gives Insight into SQL’s History
jOOQ Tuesdays: Markus Winand is on a Modern SQL Mission
Welcome to the jOOQ Tuesdays series. In this series, we’ll publish an article on the third Tuesday every other month where we interview someone we find exciting in our industry from a jOOQ perspective. This includes people who work with SQL, Java, Open Source, and a variety of other related topics. We are excited to … Continue reading jOOQ Tuesdays: Markus Winand is on a Modern SQL Mission
Use this Neat Window Function Trick to Calculate Time Differences in a Time Series
Whenever you feel that itch... Can't I calculate this with SQL? The answer is: Yes you can! And you should! Let's see how... Calculating time differences between rows Let's consider the following database containing timestamps (e.g. in a log database). We're using PostgreSQL syntax for this: CREATE TABLE timestamps ( ts timestamp ); INSERT INTO … Continue reading Use this Neat Window Function Trick to Calculate Time Differences in a Time Series
How to Extract a Date Part in SQL
The Modern SQL Twitter account (by Markus Winand) published a hint about how to extract a date part in SQL: https://twitter.com/ModernSQL/status/570294338124697600 Is it true? Yes it is, in the SQL standard and in a variety of standards-compliant databases. But let's check what jOOQ does when you run the following program on all 18 currently supported … Continue reading How to Extract a Date Part in SQL
Still Using Windows 3.1? So why stick to SQL-92?
We've been blogging a lot about the merits of modern SQL on the jOOQ blog. Specifically, window functions are one of the most fascinating features. But there are many many others. Markus Winand, author of the popular book SQL Performance Explained has recently given a very well-researched talk about modern SQL. We particularly like his … Continue reading Still Using Windows 3.1? So why stick to SQL-92?
Do You Really Understand SQL’s GROUP BY and HAVING clauses?
There are some things in SQL that we simply take for granted without thinking about them properly. One of these things are the GROUP BY and the less popular HAVING clauses. Let's look at a simple example. For this example, we'll reiterate the example database we've seen in this previous article about the awesome LEAD(), … Continue reading Do You Really Understand SQL’s GROUP BY and HAVING clauses?