DuckDB provides us with the list_has_any()
function that enables us to find any overlapping elements across two lists. The way it works is that we pass two lists, and it returns true
or false
, depending on whether any element exists in both lists.
Category: DuckDB
4 Ways to Get the ISO Year from a Date in DuckDB
In the ISO-8601 calendar, years begin on the first Monday closest to January 1, meaning the start date can fall between December 29 and January 4. This differs from the Gregorian calendar, where years always start on January 1, leading to potential discrepancies around these dates. Additionally, ISO-8601 years, or just ISO years, can be either 52 or 53 weeks long, depending on their starting point.
This article provides four options for extracting the ISO year from a date in DuckDB, accounting for these unique calendar rules.
Continue readingUnderstanding LIST_ZIP() in DuckDB
DuckDB has a list_zip()
function that zips one or more lists to a new list with a length of the longest list provided. The new list contains unnamed structs of the elements from the original lists. We pass the lists to the function when we call it. We can also pass a Boolean value to specify whether or not to truncate all lists to the smallest list.
Below are some basic examples that demonstrate how the list_zip()
function works.
Fix “Macro function generate_subscripts(arr, dim) requires 2 positional arguments” in DuckDB
If you’re getting an error that reads something like “Macro function generate_subscripts(arr, dim) requires 2 positional arguments” in DuckDB, it appears that you’re calling the generate_subscripts()
function with the wrong number of arguments.
Subtracting Minutes from a Date/Time Value in DuckDB
DuckDB provides us with the means to add and subtract intervals to/from date, timestamp, and time values. We can perform subtraction with the minus (-
) operator or the date_add()
function (along with the minus operator).
Below are examples of using each method to subtract minutes from date/time values.
Continue readingHow to Output Query Results as Pipe-Separated Lists in the DuckDB CLI
This tutorial walks you through outputting DuckDB query results in list format, which presents each record as a pipe-separated list of values. This format is handy for data processing tasks and when working with tools that expect pipe-delimited input.
Continue readingUnderstanding DuckDB’s LIST_GRADE_UP() Function
Among DuckDB’s many tools for handling list data is the list_grade_up()
function. This function works similarly to a sort operation, but instead of returning the sorted values themselves, it returns the indexes that represent the positions of those values in the original list.
Let’s take a quick look.
Continue readingUsing LIST_UNIQUE() to Count the Unique Elements of a List in DuckDB
If you ever find yourself in the situation where you need to count up the number of unique elements in a list in DuckDB, you’ll be happy to know that there’s a list_unique()
function that does exactly that.
How LIST_SELECT() Works in DuckDB
DuckDB’s list_select()
function allows us to extract specific elements from list columns based on their positions. This can be useful when we need to access or manipulate elements within arrays or lists.
Fix “No function matches the given name and argument types” When Using GENERATE_SUBSCRIPTS() in DuckDB
If you’re getting an error that reads something like “No function matches the given name and argument types” when using the generate_subscripts()
function in DuckDB, it could be that your first argument is not an array. Or it could be that your second argument is not compatible with the INT64
type.