error: INSERT has more expressions than target columns

When the parameterized PostgreSQL statement has more elements in the “VALUES” option than the number of columns specified, we get the error message:

error: INSERT has more expressions than target columns

In the sample code below there are two columns listed, and there are three elements in the “VALUES” option.

      const query = "INSERT INTO my_table (name, description) VALUES ($1, $2, $3)";

Solution

Remove the extra elements from the “VALUES” option.

Leave a comment

Your email address will not be published. Required fields are marked *