Error
Error Code:
22P04
PostgreSQL Error 22P04: Bad Copy File Format
Description
This Data Exception (22P04) indicates a problem during a `COPY` operation when importing data into a PostgreSQL table. It typically occurs when the format of the source file does not align with the `COPY` command's specifications or the target table's structure.
Error Message
bad copy file format
Known Causes
4 known causesMismatched Delimiter or Format Options
The delimiter (e.g., comma, tab) or other format options (e.g., `CSV`, `TEXT`) specified in the `COPY` command do not match the actual structure of the input file.
Data Type Inconsistencies
The data within the input file cannot be correctly converted to the corresponding column's data type in the target PostgreSQL table (e.g., text in a numeric column).
Incorrect Column Count
The number of columns or fields in the input file's rows does not match the number of columns expected by the `COPY` command or the target table definition.
Character Encoding Discrepancy
The character encoding of the input file (e.g., UTF-8, LATIN1) differs from the database's or session's expected encoding, leading to parsing failures.
Solutions
Coming SoonGeneral Troubleshooting Tips
- Check the error message carefully for specific details
- Review recent changes that might have caused the error
- Search for the exact error code in the official documentation
- Check log files for additional context
- Try restarting the application or service