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.
Tag: functions
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 readingUsing DATE_PART() to Extract Date and Time Components in DuckDB
DuckDB provides us with a good selection of functions for working with date/time values. Among them is date_part()
, which we can use to extract specific components from dates, timestamps, and intervals.
In this article, we’ll look how the date_part()
function works, along with some basic examples.
Looking at DuckDB’s STRING_AGG() Function
DuckDB has a string_agg()
function, which allows us to concatenate strings from a group of rows into a single string. This function can be useful when we need to aggregate text data in a meaningful way.
In this article, we’ll explore how the string_agg()
function works, along with some simple examples to demonstrate its usage.
Removing Duplicates from a List in DuckDB with the LIST_DISTINCT() Function
DuckDB has a function called list_distinct()
that enables us to remove duplicate values from a list. Any value that appears more than once is “deduped” and is returned once in the resulting list.
The function also removes any NULL values.
Continue reading4 Functions That Check Whether a List Contains a Given Value in DuckDB
When working with DuckDB, we may need to determine whether a specific value exists within a list or array. Fortunately, DuckDB offers four synonymous functions that enable us to accomplish this.
Continue readingUnnesting Lists & Structs with DuckDB’s UNNEST() Function
DuckDB has an unnest()
function that we can use to unnest lists and structs. Well, it can also be applied to NULL
, but that’ll return an empty result.
By “unnest” I mean it takes the list or struct, and it returns its contents as rows in a table. You might say that it converts lists and structs into tables, where each item in the list or struct becomes a row in the table.
Below are examples of using DuckDB’s unnest()
function to unnest lists and structs.
Understanding the GREATEST() Function in DuckDB
The GREATEST()
function in DuckDB is a versatile utility that returns the greatest value from a list of expressions. The function works across various data types and provides flexible comparison capabilities for data analysis tasks.
This article takes a look at DuckDB’s GREATEST()
function, along with some simple examples.
Check if a Sub-List Appears in a Larger List in DuckDB: LIST_HAS_ALL()
When working with lists in DuckDB, we sometimes need to check whether a list contains specific elements. The list_has_all()
function is a handy tool that allows us to verify if all elements of one list exist within another. This function is particularly useful in filtering queries, data validation, and advanced list-based operations.
In this article, we’ll explore how list_has_all()
works in DuckDB.