Skip to content
Advertisement

sqlite3 INSERT INTO UNION SELECT

Table columns:

pk is the auto-incrementing primary key

An error occurs when I execute this SQL

DB Error: 1 “table table1 has 4 columns but 3 values were supplied”

Advertisement

Answer

You should explicitly specify which columns in table1 your insert is targeting:

When you omit the select list entirely, SQLite will fall back to expecting values for all columns in the table, in the exact order specified by the table definition. In your case, as you only provided values for 3 out of the 4 total columns, you get an error. Note that you could have also used VALUES here:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement