Fix “Parse error: all VALUES must have the same number of terms” in SQLite when using the VALUES Stand Alone Statement

If you’re getting an error that reads “Parse error: all VALUES must have the same number of terms” in SQLite when using the VALUES clause as a stand alone statement, it’s probably because you’re not providing the same number of columns in all rows.

When we use VALUES to create a constant table, we must provide the same number of columns in each row.

To fix this issue, be sure to provide the same number of columns across all rows.

Example of Error

Here’s an example of code that results in the error:

VALUES 
  (1, 'Fred'), 
  (2, 'Wilma'), 
  (3);

Result:

Parse error: all VALUES must have the same number of terms

I got the error because I provided two columns in the first two rows, but only one column in the third row.

Solution

To fix the error, all I need to do is provide the same number of columns in all rows:

VALUES 
  (1, 'Fred'), 
  (2, 'Wilma'), 
  (3, 'Barney');

Result:

column1  column2
-------  -------
1        Fred   
2        Wilma  
3        Barney 

In this case I added a column to the third row. Now all rows have two columns, and the results are returned as expected without error.