When working with DuckDB, sometimes we might need to get the weekday name from a date or timestamp value. And sometimes we might want just the abbreviated weekday name, rather than the full name. For example, we might want Mon instead of Monday.
Continue readingCategory: DBMS
Database Management Systems
Fix “Could not convert string ‘…’ to INT64” When Using the GENERATE_SUBSCRIPTS() Function in DuckDB
If you’re getting an error that reads something like “Could not convert string ‘…’ to INT64” when using the generate_subscripts()
function in DuckDB, it appears that your second argument is a string, when it should be an integer.
DuckDB’s generate_subscripts()
function accepts two arguments; the array as the first argument, and the dimension as the second argument. The second argument must be INT64
(or be able to be implicitly converted to that type). Passing the wrong data type as the second argument can cause the above error to occur.
To fix this issue, make sure that the second argument is compatible with INT64
.
Taking a Look at the LEAST() Function in DuckDB
In DuckDB, the LEAST()
function returns the smallest value from a list of expressions. The function works across various data types and provides flexible comparison capabilities for data analysis tasks.
In this article, we’ll explore DuckDB’s LEAST()
function with some simple examples.
Understanding EXTRACT() in DuckDB
DuckDB offers a variety of date functions, one of which is the extract()
function. This function is designed to retrieve a specific date part from a date or timestamp value, and it can also be applied to intervals.
In this article, we’ll take a closer look at the extract()
function and provide some straightforward examples to illustrate how it works.
Adding Quotes Around Field Values When Outputting DuckDB Query Results as a List
In this article we look at how to automatically enclose values in single quotes when outputting DuckDB query results as a list. Using this method, each value is formatted as SQL literals. This can be useful when you want to escape the values for SQL or for some other purpose.
We also look at how CSV output is sometimes quoted with double quotes, and how we can adjust the results by doing things like removing the headers and changing the list separator.
Continue reading4 Ways to Check Your DuckDB Version
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 readingAdd 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 readingExploring the RANGE() Function in DuckDB
The range()
function is a handy utility in DuckDB that enables us to generate sequences of numbers or timestamps. We specify the starting point, the end point, and the step to use for each value in the range.
In this article, we’ll take a look at DuckDB’s range()
function, along with some basic examples.
Find 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.