2002-04-05 13:56:55 +02:00
|
|
|
--
|
|
|
|
-- insert with DEFAULT in the target_list
|
|
|
|
--
|
|
|
|
create table inserttest (col1 int4, col2 int4 NOT NULL, col3 text default 'testing');
|
|
|
|
insert into inserttest (col1, col2, col3) values (DEFAULT, DEFAULT, DEFAULT);
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: null value in column "col2" violates not-null constraint
|
2002-04-05 13:56:55 +02:00
|
|
|
insert into inserttest (col2, col3) values (3, DEFAULT);
|
|
|
|
insert into inserttest (col1, col2, col3) values (DEFAULT, 5, DEFAULT);
|
|
|
|
insert into inserttest values (DEFAULT, 5, 'test');
|
|
|
|
insert into inserttest values (DEFAULT, 7);
|
|
|
|
select * from inserttest;
|
|
|
|
col1 | col2 | col3
|
|
|
|
------+------+---------
|
|
|
|
| 3 | testing
|
|
|
|
| 5 | testing
|
|
|
|
| 5 | test
|
|
|
|
| 7 | testing
|
|
|
|
(4 rows)
|
|
|
|
|
2002-04-24 04:22:54 +02:00
|
|
|
--
|
|
|
|
-- 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)
|
|
|
|
|
2002-04-05 13:56:55 +02:00
|
|
|
drop table inserttest;
|