Index: src/backend/parser/analyze.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/parser/analyze.c,v retrieving revision 1.229 diff -c -r1.229 analyze.c *** src/backend/parser/analyze.c 2002/04/12 19:11:49 1.229 --- src/backend/parser/analyze.c 2002/04/15 02:03:51 *************** *** 547,556 **** } /* ! * XXX It is possible that the targetlist has fewer entries than were ! * in the columns list. We do not consider this an error. Perhaps we ! * should, if the columns list was explicitly given? */ /* done building the range table and jointree */ qry->rtable = pstate->p_rtable; --- 547,558 ---- } /* ! * Ensure that the targetlist has the same number of entries ! * that were present in the columns list. Don't do the check ! * for select statements. */ + if (stmt->cols != NIL && (icolumns != NIL || attnos != NIL)) + elog(ERROR, "INSERT has more target columns than expressions"); /* done building the range table and jointree */ qry->rtable = pstate->p_rtable; *************** *** 3245,3251 **** } } ! result = NIL; result = nconc(result, cxt.tables); result = nconc(result, cxt.views); result = nconc(result, cxt.grants); --- 3247,3253 ---- } } ! result = NIL; result = nconc(result, cxt.tables); result = nconc(result, cxt.views); result = nconc(result, cxt.grants); Index: src/test/regress/expected/insert.out =================================================================== RCS file: /projects/cvsroot/pgsql/src/test/regress/expected/insert.out,v retrieving revision 1.1 diff -c -r1.1 insert.out *** src/test/regress/expected/insert.out 2002/04/05 11:56:55 1.1 --- src/test/regress/expected/insert.out 2002/04/15 02:03:55 *************** *** 17,20 **** --- 17,40 ---- | 7 | testing (4 rows) + -- + -- insert with similar expression / target_list values (all fail) + -- + insert into inserttest (col1, col2, col3) values (DEFAULT, DEFAULT); + ERROR: INSERT has more target columns than expressions + insert into inserttest (col1, col2, col3) values (1, 2); + ERROR: INSERT has more target columns than expressions + insert into inserttest (col1) values (1, 2); + ERROR: INSERT has more expressions than target columns + insert into inserttest (col1) values (DEFAULT, DEFAULT); + ERROR: INSERT has more expressions than target columns + select * from inserttest; + col1 | col2 | col3 + ------+------+--------- + | 3 | testing + | 5 | testing + | 5 | test + | 7 | testing + (4 rows) + drop table inserttest; Index: src/test/regress/sql/insert.sql =================================================================== RCS file: /projects/cvsroot/pgsql/src/test/regress/sql/insert.sql,v retrieving revision 1.1 diff -c -r1.1 insert.sql *** src/test/regress/sql/insert.sql 2002/04/05 11:56:55 1.1 --- src/test/regress/sql/insert.sql 2002/04/15 02:03:55 *************** *** 9,12 **** --- 9,22 ---- insert into inserttest values (DEFAULT, 7); select * from inserttest; + + -- + -- insert with similar expression / target_list values (all fail) + -- + insert into inserttest (col1, col2, col3) values (DEFAULT, DEFAULT); + insert into inserttest (col1, col2, col3) values (1, 2); + insert into inserttest (col1) values (1, 2); + insert into inserttest (col1) values (DEFAULT, DEFAULT); + + select * from inserttest; drop table inserttest;