How to determine which column is implicated in "value too long for type character varying"?

Many thanks to @Tometzky, whose comment pointed me in the right direction.

Rather than trying to determine which column caused the problem after the fact, I modified my Python script to ensure that the value was truncated before inserting into the database.

  1. access the table's schema using select column_name, data_type, character_maximum_length from information_schema.columns where table_name='test'

  2. when building the INSERT statement, use the schema definition to identify character fields and truncate if necessary