Fix “Unrecognized format for strftime/strptime: %” 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 reading

Why SQLite Allows NULL Values in Primary Key Columns

SQLite, 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.

Continue reading

Using the .nullvalue Command to See NULL Output in the DuckDB CLI

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.

Continue reading

Understanding the STRPTIME() Function in DuckDB

DuckDB provides us with a good selection of date/time functions. The strptime() function is a useful one for times where you need to convert a date string into a valid timestamp value; its sole purpose is to parse strings into timestamps.

In this article, we’ll look at how the strptime() function works, along with some examples to demonstrate.

Continue reading