* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.231 2002/04/17 20:57:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.232 2002/04/24 02:22:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
}
/*
- * 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?
+ * 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;
}
}
- result = NIL;
+ result = NIL;
result = nconc(result, cxt.tables);
result = nconc(result, cxt.views);
result = nconc(result, cxt.grants);
| 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;
insert into inserttest values (DEFAULT, 5, 'test');
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;