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.
Author: Ian
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.
A Quick Overview of LIST_REVERSE_SORT() in DuckDB
While it’s true that DuckDB has a list_sort()
function that allows us to sort lists, it’s also true that there’s a list_reverse_sort()
function that sorts lists in reverse order.
Using LIST_REVERSE() to Reverse the Items in a List in DuckDB
Deep amongst DuckDB’s vast selection of list functions lies the list_reverse()
function. This function reverses the elements in a list. We simply pass the list to the function and it reverses the order of the elements in that list.
Not to be confused with the list_sort()
or list_reverse_sort()
functions, the list_reverse()
function reverses the order of the items as they currently sit in the list. The ...sort()
functions on the other hand, actually perform a sort operation on the list items.
A Look at DuckDB’s LIST_SORT() Function
DuckDB has a list_sort()
function that does exactly what its name promises; sorts lists.
While the easiest way to use this function is to simply pass a list, we can also pass other arguments to fine-tune the results.
Continue reading