PostgreSQL|ERROR: INSERT has more expressions than target columns -- Cause and Solution

When executing an INSERT in PostgreSQL,

ERROR: INSERT has more expressions than target columns

you may encounter this error. In such cases, there is likely a mistake in the SQL used for the INSERT operation.

Example of SQL that produces the error

insert into nobuneko_table (
nobuneko_year,
nobuneko_title
) values (
2011,
'猫大好き',
'温泉も好きです'
);

In the example above, there are two columns -- "nobuneko_year" and "nobuneko_title" -- but three values are provided. Because the number of values exceeds the number of columns, the error occurs.

Cause of the error and how to resolve it

To resolve this error, simply make sure that the number of columns and the number of values in the INSERT statement match.

Example of SQL that does not produce the error

insert into nobuneko_table (
nobuneko_year,
nobuneko_title,
nobuneko_comment
) values (
2011,
'猫大好き',
'温泉も好きです'
);

前へ

PostgreSQL|ERROR: INSERT has more expressions than target columns の原因と解決方法

次へ

久しぶりに午前0時過ぎには家に帰れた