Data Type Mismatch
Error message
column is of type integer but expression is of type text
Quick summary
The value you are inserting or comparing does not match the column's data type — e.g., text into an integer column.
Why this happens
Inserting a string into an integer or numeric column
Comparing a column to a value of a different type in a WHERE clause
Application sends the wrong type (e.g., a string instead of a number)
Missing type conversion (CAST or ::)
Minimal example
INSERT INTO users (id, name) VALUES ('abc', 'Ada');
-- id is INTEGER but 'abc' is textINSERT INTO users (id, name) VALUES (1, 'Ada');The id column is INTEGER, so it needs a number, not a string. Using a numeric value fixes the error.
How to diagnose
Read the error to see which column and which type were expected vs provided
Check the column's data type:
\d table_nameCheck the value your application is sending
How to fix
Send the correct type from your application
Use explicit type conversion:
CAST(value AS type)orvalue::typeChange the column type if the schema is wrong
How to prevent
Use parameterized queries with correct types — the driver handles conversion
Validate data types in your application before inserting
Use an ORM that maps types automatically
Related Resources
Related Glossary
Related Lessons
- Tables
Learn about column data types.