# Conversion Error: The value cannot be cast to the target type

> A cast or implicit conversion met a value it cannot represent in the destination type, such as 'abc' as an integer.

Source: https://sqlly.app/errors/duckdb/conversion-could-not-convert
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Exception: `Conversion Error`
- Category: Conversion and range errors

Error message:

```text
Conversion Error: Could not convert string 'abc' to INT32
```

## What it means

DuckDB applies casts eagerly: a comparison between text and a number, a COPY into a typed table, or a CSV import all convert values, and the first bad value raises `Conversion Error`. The message shows the offending value and the destination type, for example `Could not convert string 'abc' to INT32`.

Conversion and parsing are related but distinct. `Could not convert string` covers plain casts; malformed dates give their own wording (`invalid date field format: "31/12/2024", expected format is (YYYY-MM-DD)`), malformed timestamps give `invalid timestamp field format` with their own expected format, and an impossible but well-formed value gives `date field value out of range` (or `timestamp field value out of range`). Arithmetic overflow gives `Out of Range Error` instead.

## Common causes

- A text value with letters, spaces or a wrong separator cast to a numeric type.
- A CSV read with an explicit numeric column type, or a COPY into a typed table, where some rows hold text. Auto-detection does not fail on this: it infers VARCHAR for the column.
- An implicit cast in a comparison where the two sides have different types, such as `'abc' = 5`.
- A malformed date, time or timestamp string that does not match the expected format.

## How to fix it

1. Find the bad values before casting, so the fix is data-driven:

   ```sql
   SELECT raw_value FROM stage
   WHERE raw_value IS NOT NULL AND NOT regexp_matches(raw_value, '^-?[0-9]+$');
   ```
2. Cast with TRY_CAST, which returns NULL for values it cannot convert instead of failing the query:

   ```sql
   SELECT TRY_CAST(raw_value AS INTEGER) FROM stage;
   ```
3. For CSV files, scan everything as VARCHAR first and convert explicitly with a rule:

   ```sql
   CREATE TABLE stage AS
   SELECT * FROM read_csv('input.csv', all_varchar = true);
   SELECT TRY_CAST(amount AS DECIMAL(12,2)) FROM stage;
   ```
4. Parse nonstandard formats with a format hint rather than a plain cast:

   ```sql
   SELECT strptime(ts_text, '%d/%m/%Y %H:%M') FROM events;
   ```

## Reproduce it safely

```sql
SELECT 'abc'::INTEGER;   -- Conversion Error: Could not convert string 'abc' to INT32
```

## Questions

### How do I import a CSV that has bad rows without failing the whole load?

Read with all_varchar = true into a staging table, then TRY_CAST into the typed table and review the rows that came out NULL.

### Why does the message say INT32 when my column is INTEGER?

DuckDB stores INTEGER as a 32-bit integer, so messages name the physical type. INTEGER is INT32, BIGINT is INT64, TINYINT is INT8.

## Related errors

- [`Conversion Error`](https://sqlly.app/errors/duckdb/conversion-out-of-range): The value is out of range for INT32
- [`Binder Error`](https://sqlly.app/errors/duckdb/binder-error): DuckDB could not plan the query
- [`22P02`](https://sqlly.app/errors/postgresql/22P02): PostgreSQL: invalid input syntax for type
- [`22003`](https://sqlly.app/errors/postgresql/22003): PostgreSQL: numeric value out of range
- [`SQLITE_ERROR`](https://sqlly.app/errors/sqlite/sqlite-error): SQLite: SQL logic error

The code and message text are from the [DuckDB documentation](https://duckdb.org/docs/).
