Using Multiple CTEs in a Single Query

Common Table Expressions (CTEs) are a handy way to break down a complex query into readable, reusable pieces. When you need several intermediate results – say, a filtered set, an aggregation, and a ranking – you can stack multiple CTE definitions together. PostgreSQL, SQL Server, MySQL 8+, and many other engines support this syntax.

Read more

7 Ways to Extract Data from JSON in DuckDB

Most DuckDB distributions come with the JSON extension, and this extension is loaded upon first use. That means we can go ahead and run queries against JSON data right out of the box. One common task we’ll face when working with JSON is extracting data from within the JSON documents. This can include extracting scalar values, or extracting nested JSON from within the outer document.

DuckDB provides us with multiple ways to extract such data. The option we use will largely depend on our use case. Either way, here are seven options for extracting data from JSON documents in DuckDB.

Read more

The Difference Between LIST_SELECT() and LIST_SLICE() in DuckDB

DuckDB has a list_select() function and a list_slice() function, and both do a similar thing. They allow us to extract values from lists based on their index in the list. But they’re quite different in the way they work. One function allows us to select elements based on a range, while the other function allows us to handpick each element we want returned.

Read more

5 Functions that Extract the Month from a Date in DuckDB

Sometimes when working with SQL databases like DuckDB, we need to return the month part from a date for presentation or for further processing. DuckDB provides us with a handful of functions that can help in this regard.

In this article, we’ll look at five different functions we can use to extract the month from a date in DuckDB.

Read more

Quick Overview of the List Operators in DuckDB

DuckDB provides us with a bunch of functions and operators that we can use when working with lists. These include operators for doing things like concatenating lists to performing calculations on the lists. Most of these operators are aliases for a corresponding function, so we can choose which one to use in those cases.

This article provides an overview of the six list operators available in DuckDB, along with basic examples to demonstrate their usage.

Read more