When using PostgreSQL’s EXCEPT
operator, if you encounter an error that reads “ERROR: each EXCEPT query must have the same number of columns“, it’s because there’s a mismatch in the number of columns returned by the queries on either side of the EXCEPT
operator.
The way to fix this is to ensure that both SELECT
statements return the same number of columns.