DuckDB 0.10: Binder Error: No function matches the given name and argument types
In the 0.10 version of DuckDB, a breaking change was made that stops implicit casting to VARCHAR
during function binding.
In this blog post, we’re going to look at some ways to work around this change when fixing our DuckDB code from 0.9 or earlier.
I have a CSV file that looks like this:
from 'people.csv' select *;
┌─────────┬─────────────┐
│ name │ dateOfBirth │
│ varchar │ int64 │
├─────────┼─────────────┤
│ John │ 19950105 │
└─────────┴─────────────┘
The dateOfBirth
column isn’t an int64
, but that’s how DuckDB has inferred it.
I was then using the strptime
function to convert the value to a TIMESTAMP
:
from 'people.csv' select strptime(dateOfBirth, '%Y%m%d');
This results in the following error:
Error: Binder Error: No function matches the given name and argument types 'strptime(BIGINT, STRING_LITERAL)'. You might need to add explicit type casts.
Candidate functions:
strptime(VARCHAR, VARCHAR) -> TIMESTAMP
strptime(VARCHAR, VARCHAR[]) -> TIMESTAMP
LINE 1: from 'people.csv' select strptime(dateOfBirth, '%Y%m%d');
One way to fix this is to cast dateOfBirth
, like this:
from 'people.csv' select strptime(dateOfBirth::STRING, '%Y%m%d') AS dob;
┌─────────────────────┐
│ dob │
│ timestamp │
├─────────────────────┤
│ 1995-01-05 00:00:00 │
└─────────────────────┘
Alternatively, we could use the read_csv_auto
function and specify the type for dateOfBirth
via the types
parameters:
from read_csv_auto('people.csv', types={"dateOfBirth": "STRING"})
select strptime(dateOfBirth, '%Y%m%d') AS dob;
┌─────────────────────┐
│ dob │
│ timestamp │
├─────────────────────┤
│ 1995-01-05 00:00:00 │
└─────────────────────┘
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.