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.

Continue reading

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).

Continue reading

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.

Continue reading

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 date_part() to try to get the month name from a date.

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.

Continue reading

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

Fix “Binder Error” When Using COALESCE() in DuckDB

If you’re getting an error that reads something like “Binder Error: Cannot mix values of type …etc” when using the COALESCE() function in DuckDB, it’s probably because 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).

Continue reading