If you’re using DuckDB and you need to check which version you’re running, here are some quick and easy methods to do so.
Continue readingTag: how to
Add Seconds to a Date/Time Value in DuckDB
Performing date/time arithmetic is a common operation when using SQL databases such as DuckDB. As with most RDBMSs, DuckDB makes these types of operations relatively straightforward for us.
Here are two options for adding one or more seconds to a date, timestamp, or time value.
Continue readingSampling Rows from a Table in DuckDB with the SAMPLE Clause
DuckDB’s SAMPLE
clause is a handy feature that allows us to work with a random subset of our data. This is particularly useful when dealing with large datasets where processing the entire dataset might be time-consuming or unnecessary for exploratory data analysis, testing queries, or creating representative samples.
When we use this clause, we can specify the absolute number of rows to return, or a percentage of rows. We also have an option of sampling method to use.
Continue readingFind Out if a Table is WITHOUT ROWID in SQLite
One of SQLite’s unique features is the WITHOUT ROWID
table, which can be used to optimize performance and storage in specific scenarios.
While it’s easy enough to create a WITHOUT ROWID
table (just add WITHOUT ROWID
to the definition), how to identify a WITHOUT ROWID
table might not be so obvious.
In this article, we’ll start by briefly revising what WITHOUT ROWID
tables are and how they differ from ordinary tables. Then we’ll look at how to identify these tables by using SQLite’s PRAGMA commands.
Fixing “Conversion Error” When Using COALESCE() in DuckDB
If you’re getting an error that reads “Conversion Error: Could not convert …etc” while using the COALESCE()
function in DuckDB, it appears that you’re using arguments with incompatible types.
To fix this issue, try using CAST()
or TRY_CAST()
to ensure that all arguments are compatible. Alternatively, make sure the arguments to COALESCE()
are of the same type (or at least, compatible types).
Using TRY_STRPTIME() to Handle Errors When Constructing Timestamps in DuckDB
If you’ve ever used the strptime()
function to create a timestamp in DuckDB, you may be aware that it will return an error if it can’t construct the timestamp from the format string/s provided.
While such an error could be useful in some situations, it could also be annoying in others.
Fortunately, DuckDB also provides the try_strptime()
function, which will suppress any error that we might ordinarily get in such cases. This function returns null instead of an error.
Using the AGE() Function to Compare Dates in DuckDB
When working with date and time data in DuckDB, calculating the difference between two dates is a common requirement. Whether we’re determining a person’s age from their birthdate or measuring the duration between two events, DuckDB’s age()
function provides a straightforward solution. This function returns an interval representing the difference between two timestamps or dates, making it especially useful for time-based analyses.
In this article, we’ll explore how to use the age()
function in DuckDB. We’ll cover its syntax, and provide some simple examples.
Fix ‘Conversion Error: extract specifier “monthname” not recognized’ in DuckDB
If you’re getting an error that reads “Conversion Error: extract specifier “monthname” not recognized” in DuckDB, it appears that you’re using a function like extract()
or
to try to get the month name from a date.date_part()
These functions don’t accept a monthname
specifier, and so that’s why the error occurs. Fortunately, DuckDB provides a monthname()
function, and so you could try that instead. Also, the strftime()
function has a format specifier for the month name, and so that’s another option.
So to fix this issue, try the monthname()
or strftime()
function instead.
Checking if a Value is Finite in DuckDB with ISFINITE()
In DuckDB, ISFINITE()
is a function for checking whether values are finite. DuckDB supports infinite values, and so we can use this function to check whether a value is infinite or not. This can be useful when working with floating-point data that might contain special values like NaN (Not a Number) or infinity. We can also use it on date and timestamp values.
2 Ways to Add Years to a Date in DuckDB
DuckDB provides us with an easy way to add one or more time intervals to date values. This includes adding one or more years to a date.
Here are two options for adding one or more years to a date in DuckDB.
Continue reading