DuckDB is an in-process SQL OLAP database management system designed for analytical workloads. Among its many functions is one called last()
. This function returns the last value in a column.
Let’s take a look at the last()
function in DuckDB.
Database Management Systems
DuckDB is an in-process SQL OLAP database management system designed for analytical workloads. Among its many functions is one called last()
. This function returns the last value in a column.
Let’s take a look at the last()
function in DuckDB.
Both AGE()
and DATE_DIFF()
are DuckDB functions used to calculate time differences, but they serve distinct purposes and exhibit different behaviors that are important to understand when working with temporal data.
This article explores the difference between these two functions.
Continue readingIn DuckDB, the make_date()
function enables us to create date values from individual year, month, and day components. This function is particularly useful when working with data that stores date components separately or when constructing date values programmatically.
Working with dates often requires extracting specific components, such as the week number, for analysis or reporting. In DuckDB, there are multiple functions to retrieve the week from a date, each catering to different needs. This article explores four such functions, including how to calculate the ISO week—a standard defined by ISO-8601 where weeks start on Monday and the first week of the year contains the year’s first Thursday.
Continue readingDuckDB has a max_by()
function that finds the row with the maximum value in one column and returns the corresponding value from another column at that row.
Below are some examples that demonstrate how it works.
Continue readingOne of the aggregate functions available in DuckDB is the FIRST()
function, which returns the first value from each group in a query.
Let’s take a look at some examples of using the FIRST()
function in DuckDB
If you’re getting an error that includes the text “Unrecognized format for strftime/strptime: %” in DuckDB, it appears that you’re including an unescaped percent sign (%
) in your format string when using a function like strftime()
or strptime()
.
Whenever we need a percent sign to be included in the formatted output, we must escape it with another percent sign in the format string.
So to fix this issue, try escaping the percent sign with another percent sign.
Continue readingDuckDB provides us with a range of functions and operators that we can use to manipulate date, time, and timestamp values. One basic operation you might find yourself having to perform is date/time arithmetic, such as adding one or more hours to a date/time value.
Below are two methods we can use in order to add one or more hours to a date, timestamp, or time value.
Continue readingSQLite, one of the most widely used database engines, is known for its lightweight design, ease of use, and adherence to most aspects of the SQL standard. However, one notable deviation from the standard lies in its handling of PRIMARY KEY
constraints. Unlike the SQL standard, SQLite allows NULL
values in primary key columns in some cases.
Let’s look at the reasons behind this behavior, and explore the implications of NULL
values in primary key columns. We’ll also examine SQLite’s treatment of NULL
values as distinct for uniqueness constraints.
By default, when a query returns a null value in the DuckDB command line interface (CLI), an empty string is displayed. This may or may not be what you want. But if you’re like me, you probably want DuckDB to explicitly tell you that it’s a null value. After all, if an empty string is returned, perhaps the data contained an empty string?
Fortunately, DuckDB provides us with the .nullvalue
dot command so that we can change the output of null values.