Index: src/test/regress/expected/alter_table.out
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/expected/alter_table.out,v
retrieving revision 1.38
diff -c -r1.38 alter_table.out
*** src/test/regress/expected/alter_table.out	12 Apr 2002 20:38:30 -0000	1.38
--- src/test/regress/expected/alter_table.out	16 Apr 2002 20:22:30 -0000
***************
*** 681,683 ****
--- 681,739 ----
  ERROR:  ExecAppend: Fail to add null value in not null attribute a
  drop table child;
  drop table parent;
+ -- test setting and removing default values
+ create table def_test (
+ 	c1	int4 default 5,
+ 	c2	text default 'initial_default'
+ );
+ insert into def_test default values;
+ alter table def_test alter column c1 drop default;
+ insert into def_test default values;
+ alter table def_test alter column c2 drop default;
+ insert into def_test default values;
+ alter table def_test alter column c1 set default 10;
+ alter table def_test alter column c2 set default 'new_default';
+ insert into def_test default values;
+ select * from def_test;
+  c1 |       c2        
+ ----+-----------------
+   5 | initial_default
+     | initial_default
+     | 
+  10 | new_default
+ (4 rows)
+ 
+ -- set defaults to an incorrect type: this should fail
+ alter table def_test alter column c1 set default 'wrong_datatype';
+ ERROR:  pg_atoi: error in "wrong_datatype": can't parse "wrong_datatype"
+ alter table def_test alter column c2 set default 20;
+ -- set defaults on a non-existent column: this should fail
+ alter table def_test alter column c3 set default 30;
+ ERROR:  ALTER TABLE: relation "def_test" has no column "c3"
+ -- set defaults on views: we need to create a view, add a rule
+ -- to allow insertions into it, and then alter the view to add
+ -- a default
+ create view def_view_test as select * from def_test;
+ create rule def_view_test_ins as
+ 	on insert to def_view_test
+ 	do instead insert into def_test select new.*;
+ insert into def_view_test default values;
+ alter table def_view_test alter column c1 set default 45;
+ insert into def_view_test default values;
+ alter table def_view_test alter column c2 set default 'view_default';
+ insert into def_view_test default values;
+ select * from def_view_test;
+  c1 |       c2        
+ ----+-----------------
+   5 | initial_default
+     | initial_default
+     | 
+  10 | new_default
+     | 
+  45 | 
+  45 | view_default
+ (7 rows)
+ 
+ drop rule def_view_test_ins;
+ drop view def_view_test;
+ drop table def_test;
Index: src/test/regress/sql/alter_table.sql
===================================================================
RCS file: /var/lib/cvs/pgsql/src/test/regress/sql/alter_table.sql,v
retrieving revision 1.25
diff -c -r1.25 alter_table.sql
*** src/test/regress/sql/alter_table.sql	12 Apr 2002 20:38:31 -0000	1.25
--- src/test/regress/sql/alter_table.sql	16 Apr 2002 20:22:30 -0000
***************
*** 532,534 ****
--- 532,573 ----
  drop table child;
  drop table parent;
  
+ -- test setting and removing default values
+ create table def_test (
+ 	c1	int4 default 5,
+ 	c2	text default 'initial_default'
+ );
+ insert into def_test default values;
+ alter table def_test alter column c1 drop default;
+ insert into def_test default values;
+ alter table def_test alter column c2 drop default;
+ insert into def_test default values;
+ alter table def_test alter column c1 set default 10;
+ alter table def_test alter column c2 set default 'new_default';
+ insert into def_test default values;
+ select * from def_test;
+ 
+ -- set defaults to an incorrect type: this should fail
+ alter table def_test alter column c1 set default 'wrong_datatype';
+ alter table def_test alter column c2 set default 20;
+ 
+ -- set defaults on a non-existent column: this should fail
+ alter table def_test alter column c3 set default 30;
+ 
+ -- set defaults on views: we need to create a view, add a rule
+ -- to allow insertions into it, and then alter the view to add
+ -- a default
+ create view def_view_test as select * from def_test;
+ create rule def_view_test_ins as
+ 	on insert to def_view_test
+ 	do instead insert into def_test select new.*;
+ insert into def_view_test default values;
+ alter table def_view_test alter column c1 set default 45;
+ insert into def_view_test default values;
+ alter table def_view_test alter column c2 set default 'view_default';
+ insert into def_view_test default values;
+ select * from def_view_test;
+ 
+ drop rule def_view_test_ins;
+ drop view def_view_test;
+ drop table def_test;
