OSDN Git Service

6eaae24fa80ce2932945d39d1b969c544c5f9860
[pg-rex/syncrep.git] / src / test / regress / sql / alter_table.sql
1 --
2 -- ALTER_TABLE
3 -- add attribute
4 --
5
6 CREATE TABLE tmp (initial int4);
7
8 ALTER TABLE tmp ADD COLUMN a int4;
9
10 ALTER TABLE tmp ADD COLUMN b name;
11
12 ALTER TABLE tmp ADD COLUMN c text;
13
14 ALTER TABLE tmp ADD COLUMN d float8;
15
16 ALTER TABLE tmp ADD COLUMN e float4;
17
18 ALTER TABLE tmp ADD COLUMN f int2;
19
20 ALTER TABLE tmp ADD COLUMN g polygon;
21
22 ALTER TABLE tmp ADD COLUMN h abstime;
23
24 ALTER TABLE tmp ADD COLUMN i char;
25
26 ALTER TABLE tmp ADD COLUMN j abstime[];
27
28 ALTER TABLE tmp ADD COLUMN k int4;
29
30 ALTER TABLE tmp ADD COLUMN l tid;
31
32 ALTER TABLE tmp ADD COLUMN m xid;
33
34 ALTER TABLE tmp ADD COLUMN n oidvector;
35
36 --ALTER TABLE tmp ADD COLUMN o lock;
37 ALTER TABLE tmp ADD COLUMN p smgr;
38
39 ALTER TABLE tmp ADD COLUMN q point;
40
41 ALTER TABLE tmp ADD COLUMN r lseg;
42
43 ALTER TABLE tmp ADD COLUMN s path;
44
45 ALTER TABLE tmp ADD COLUMN t box;
46
47 ALTER TABLE tmp ADD COLUMN u tinterval;
48
49 ALTER TABLE tmp ADD COLUMN v timestamp;
50
51 ALTER TABLE tmp ADD COLUMN w interval;
52
53 ALTER TABLE tmp ADD COLUMN x float8[];
54
55 ALTER TABLE tmp ADD COLUMN y float4[];
56
57 ALTER TABLE tmp ADD COLUMN z int2[];
58
59 INSERT INTO tmp (a, b, c, d, e, f, g, h, i, j, k, l, m, n, p, q, r, s, t, u,
60         v, w, x, y, z)
61    VALUES (4, 'name', 'text', 4.1, 4.1, 2, '(4.1,4.1,3.1,3.1)', 
62         'Mon May  1 00:30:30 1995', 'c', '{Mon May  1 00:30:30 1995, Monday Aug 24 14:43:07 1992, epoch}', 
63         314159, '(1,1)', '512',
64         '1 2 3 4 5 6 7 8', 'magnetic disk', '(1.1,1.1)', '(4.1,4.1,3.1,3.1)',
65         '(0,2,4.1,4.1,3.1,3.1)', '(4.1,4.1,3.1,3.1)', '["epoch" "infinity"]',
66         'epoch', '01:00:10', '{1.0,2.0,3.0,4.0}', '{1.0,2.0,3.0,4.0}', '{1,2,3,4}');
67
68 SELECT * FROM tmp;
69
70 DROP TABLE tmp;
71
72 -- the wolf bug - schema mods caused inconsistent row descriptors 
73 CREATE TABLE tmp (
74         initial         int4
75 );
76
77 ALTER TABLE tmp ADD COLUMN a int4;
78
79 ALTER TABLE tmp ADD COLUMN b name;
80
81 ALTER TABLE tmp ADD COLUMN c text;
82
83 ALTER TABLE tmp ADD COLUMN d float8;
84
85 ALTER TABLE tmp ADD COLUMN e float4;
86
87 ALTER TABLE tmp ADD COLUMN f int2;
88
89 ALTER TABLE tmp ADD COLUMN g polygon;
90
91 ALTER TABLE tmp ADD COLUMN h abstime;
92
93 ALTER TABLE tmp ADD COLUMN i char;
94
95 ALTER TABLE tmp ADD COLUMN j abstime[];
96
97 ALTER TABLE tmp ADD COLUMN k int4;
98
99 ALTER TABLE tmp ADD COLUMN l tid;
100
101 ALTER TABLE tmp ADD COLUMN m xid;
102
103 ALTER TABLE tmp ADD COLUMN n oidvector;
104
105 --ALTER TABLE tmp ADD COLUMN o lock;
106 ALTER TABLE tmp ADD COLUMN p smgr;
107
108 ALTER TABLE tmp ADD COLUMN q point;
109
110 ALTER TABLE tmp ADD COLUMN r lseg;
111
112 ALTER TABLE tmp ADD COLUMN s path;
113
114 ALTER TABLE tmp ADD COLUMN t box;
115
116 ALTER TABLE tmp ADD COLUMN u tinterval;
117
118 ALTER TABLE tmp ADD COLUMN v timestamp;
119
120 ALTER TABLE tmp ADD COLUMN w interval;
121
122 ALTER TABLE tmp ADD COLUMN x float8[];
123
124 ALTER TABLE tmp ADD COLUMN y float4[];
125
126 ALTER TABLE tmp ADD COLUMN z int2[];
127
128 INSERT INTO tmp (a, b, c, d, e, f, g, h, i, j, k, l, m, n, p, q, r, s, t, u,
129         v, w, x, y, z)
130    VALUES (4, 'name', 'text', 4.1, 4.1, 2, '(4.1,4.1,3.1,3.1)', 
131         'Mon May  1 00:30:30 1995', 'c', '{Mon May  1 00:30:30 1995, Monday Aug 24 14:43:07 1992, epoch}', 
132         314159, '(1,1)', '512',
133         '1 2 3 4 5 6 7 8', 'magnetic disk', '(1.1,1.1)', '(4.1,4.1,3.1,3.1)',
134         '(0,2,4.1,4.1,3.1,3.1)', '(4.1,4.1,3.1,3.1)', '["epoch" "infinity"]',
135         'epoch', '01:00:10', '{1.0,2.0,3.0,4.0}', '{1.0,2.0,3.0,4.0}', '{1,2,3,4}');
136
137 SELECT * FROM tmp;
138
139 DROP TABLE tmp;
140
141
142 --
143 -- rename -
144 --   should preserve indices, which we can check by seeing if a SELECT
145 --   chooses an indexscan; however, in the absence of vacuum statistics
146 --   it might not.  Therefore, vacuum first.
147 --
148 VACUUM ANALYZE tenk1;
149
150 ALTER TABLE tenk1 RENAME TO ten_k;
151
152 -- 20 values, sorted 
153 SELECT unique1 FROM ten_k WHERE unique1 < 20;
154
155 -- 20 values, sorted 
156 SELECT unique2 FROM ten_k WHERE unique2 < 20;
157
158 -- 100 values, sorted 
159 SELECT hundred FROM ten_k WHERE hundred = 50;
160
161 ALTER TABLE ten_k RENAME TO tenk1;
162
163 -- 5 values, sorted 
164 SELECT unique1 FROM tenk1 WHERE unique1 < 5;
165
166 -- ALTER TABLE ... RENAME on non-table relations
167 -- renaming indexes (FIXME: this should probably test the index's functionality)
168 ALTER TABLE onek_unique1 RENAME TO tmp_onek_unique1;
169 ALTER TABLE tmp_onek_unique1 RENAME TO onek_unique1;
170 -- renaming views
171 CREATE VIEW tmp_view (unique1) AS SELECT unique1 FROM tenk1;
172 ALTER TABLE tmp_view RENAME TO tmp_view_new;
173 -- 5 values, sorted 
174 SELECT unique1 FROM tenk1 WHERE unique1 < 5;
175 DROP VIEW tmp_view_new;
176 -- renaming sequences
177 CREATE SEQUENCE foo_seq;
178 ALTER TABLE foo_seq RENAME TO foo_seq_new;
179 SELECT * FROM foo_seq_new;
180 DROP SEQUENCE foo_seq_new;
181 -- toast-like relation name
182 alter table stud_emp rename to pg_toast_stud_emp;
183 alter table pg_toast_stud_emp rename to stud_emp;
184
185 -- FOREIGN KEY CONSTRAINT adding TEST
186
187 CREATE TABLE tmp2 (a int primary key);
188
189 CREATE TABLE tmp3 (a int, b int);
190
191 CREATE TABLE tmp4 (a int, b int, unique(a,b));
192
193 CREATE TABLE tmp5 (a int, b int);
194
195 -- Insert rows into tmp2 (pktable)
196 INSERT INTO tmp2 values (1);
197 INSERT INTO tmp2 values (2);
198 INSERT INTO tmp2 values (3);
199 INSERT INTO tmp2 values (4);
200
201 -- Insert rows into tmp3
202 INSERT INTO tmp3 values (1,10);
203 INSERT INTO tmp3 values (1,20);
204 INSERT INTO tmp3 values (5,50);
205
206 -- Try (and fail) to add constraint due to invalid source columns
207 ALTER TABLE tmp3 add constraint tmpconstr foreign key(c) references tmp2 match full;
208
209 -- Try (and fail) to add constraint due to invalide destination columns explicitly given
210 ALTER TABLE tmp3 add constraint tmpconstr foreign key(a) references tmp2(b) match full;
211
212 -- Try (and fail) to add constraint due to invalid data
213 ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
214
215 -- Delete failing row
216 DELETE FROM tmp3 where a=5;
217
218 -- Try (and succeed)
219 ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
220
221 -- Try (and fail) to create constraint from tmp5(a) to tmp4(a) - unique constraint on
222 -- tmp4 is a,b
223
224 ALTER TABLE tmp5 add constraint tmpconstr foreign key(a) references tmp4(a) match full;
225
226 DROP TABLE tmp5;
227
228 DROP TABLE tmp4;
229
230 DROP TABLE tmp3;
231
232 DROP TABLE tmp2;
233
234 -- Foreign key adding test with mixed types
235
236 -- Note: these tables are TEMP to avoid name conflicts when this test
237 -- is run in parallel with foreign_key.sql.
238
239 CREATE TEMP TABLE PKTABLE (ptest1 int PRIMARY KEY);
240 CREATE TEMP TABLE FKTABLE (ftest1 inet);
241 -- This next should fail, because inet=int does not exist
242 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable;
243 -- This should also fail for the same reason, but here we
244 -- give the column name
245 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable(ptest1);
246 -- This should succeed, even though they are different types
247 -- because varchar=int does exist
248 DROP TABLE FKTABLE;
249 CREATE TEMP TABLE FKTABLE (ftest1 varchar);
250 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable;
251 -- As should this
252 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable(ptest1);
253 DROP TABLE pktable cascade;
254 DROP TABLE fktable;
255
256 CREATE TEMP TABLE PKTABLE (ptest1 int, ptest2 inet,
257                            PRIMARY KEY(ptest1, ptest2));
258 -- This should fail, because we just chose really odd types
259 CREATE TEMP TABLE FKTABLE (ftest1 cidr, ftest2 timestamp);
260 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2) references pktable;
261 DROP TABLE FKTABLE;
262 -- Again, so should this...
263 CREATE TEMP TABLE FKTABLE (ftest1 cidr, ftest2 timestamp);
264 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2)
265      references pktable(ptest1, ptest2);
266 DROP TABLE FKTABLE;
267 -- This fails because we mixed up the column ordering
268 CREATE TEMP TABLE FKTABLE (ftest1 int, ftest2 inet);
269 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2)
270      references pktable(ptest2, ptest1);
271 -- As does this...
272 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest2, ftest1)
273      references pktable(ptest1, ptest2);
274
275 -- temp tables should go away by themselves, need not drop them.
276
277 -- test check constraint adding
278
279 create table atacc1 ( test int );
280 -- add a check constraint
281 alter table atacc1 add constraint atacc_test1 check (test>3);
282 -- should fail
283 insert into atacc1 (test) values (2);
284 -- should succeed
285 insert into atacc1 (test) values (4);
286 drop table atacc1;
287
288 -- let's do one where the check fails when added
289 create table atacc1 ( test int );
290 -- insert a soon to be failing row
291 insert into atacc1 (test) values (2);
292 -- add a check constraint (fails)
293 alter table atacc1 add constraint atacc_test1 check (test>3);
294 insert into atacc1 (test) values (4);
295 drop table atacc1;
296
297 -- let's do one where the check fails because the column doesn't exist
298 create table atacc1 ( test int );
299 -- add a check constraint (fails)
300 alter table atacc1 add constraint atacc_test1 check (test1>3);
301 drop table atacc1;
302
303 -- something a little more complicated
304 create table atacc1 ( test int, test2 int, test3 int);
305 -- add a check constraint (fails)
306 alter table atacc1 add constraint atacc_test1 check (test+test2<test3*4);
307 -- should fail
308 insert into atacc1 (test,test2,test3) values (4,4,2);
309 -- should succeed
310 insert into atacc1 (test,test2,test3) values (4,4,5);
311 drop table atacc1;
312
313 -- lets do some naming tests
314 create table atacc1 (test int check (test>3), test2 int);
315 alter table atacc1 add check (test2>test);
316 -- should fail for $2
317 insert into atacc1 (test2, test) values (3, 4);
318 drop table atacc1;
319
320 -- inheritance related tests
321 create table atacc1 (test int);
322 create table atacc2 (test2 int);
323 create table atacc3 (test3 int) inherits (atacc1, atacc2);
324 alter table atacc2 add constraint foo check (test2>0);
325 -- fail and then succeed on atacc2
326 insert into atacc2 (test2) values (-3);
327 insert into atacc2 (test2) values (3);
328 -- fail and then succeed on atacc3
329 insert into atacc3 (test2) values (-3);
330 insert into atacc3 (test2) values (3);
331 drop table atacc3;
332 drop table atacc2;
333 drop table atacc1;
334
335 -- let's try only to add only to the parent
336
337 create table atacc1 (test int);
338 create table atacc2 (test2 int);
339 create table atacc3 (test3 int) inherits (atacc1, atacc2);
340 alter table only atacc2 add constraint foo check (test2>0);
341 -- fail and then succeed on atacc2
342 insert into atacc2 (test2) values (-3);
343 insert into atacc2 (test2) values (3);
344 -- both succeed on atacc3
345 insert into atacc3 (test2) values (-3);
346 insert into atacc3 (test2) values (3);
347 drop table atacc3;
348 drop table atacc2;
349 drop table atacc1;
350
351 -- test unique constraint adding
352
353 create table atacc1 ( test int );
354 -- add a unique constraint
355 alter table atacc1 add constraint atacc_test1 unique (test);
356 -- insert first value
357 insert into atacc1 (test) values (2);
358 -- should fail
359 insert into atacc1 (test) values (2);
360 -- should succeed
361 insert into atacc1 (test) values (4);
362 -- try adding a unique oid constraint
363 alter table atacc1 add constraint atacc_oid1 unique(oid);
364 drop table atacc1;
365
366 -- let's do one where the unique constraint fails when added
367 create table atacc1 ( test int );
368 -- insert soon to be failing rows
369 insert into atacc1 (test) values (2);
370 insert into atacc1 (test) values (2);
371 -- add a unique constraint (fails)
372 alter table atacc1 add constraint atacc_test1 unique (test);
373 insert into atacc1 (test) values (3);
374 drop table atacc1;
375
376 -- let's do one where the unique constraint fails
377 -- because the column doesn't exist
378 create table atacc1 ( test int );
379 -- add a unique constraint (fails)
380 alter table atacc1 add constraint atacc_test1 unique (test1);
381 drop table atacc1;
382
383 -- something a little more complicated
384 create table atacc1 ( test int, test2 int);
385 -- add a unique constraint
386 alter table atacc1 add constraint atacc_test1 unique (test, test2);
387 -- insert initial value
388 insert into atacc1 (test,test2) values (4,4);
389 -- should fail
390 insert into atacc1 (test,test2) values (4,4);
391 -- should all succeed
392 insert into atacc1 (test,test2) values (4,5);
393 insert into atacc1 (test,test2) values (5,4);
394 insert into atacc1 (test,test2) values (5,5);
395 drop table atacc1;
396
397 -- lets do some naming tests
398 create table atacc1 (test int, test2 int, unique(test));
399 alter table atacc1 add unique (test2);
400 -- should fail for @@ second one @@
401 insert into atacc1 (test2, test) values (3, 3);
402 insert into atacc1 (test2, test) values (2, 3);
403 drop table atacc1;
404
405 -- test primary key constraint adding
406
407 create table atacc1 ( test int );
408 -- add a primary key constraint
409 alter table atacc1 add constraint atacc_test1 primary key (test);
410 -- insert first value
411 insert into atacc1 (test) values (2);
412 -- should fail
413 insert into atacc1 (test) values (2);
414 -- should succeed
415 insert into atacc1 (test) values (4);
416 -- inserting NULL should fail
417 insert into atacc1 (test) values(NULL);
418 -- try adding a primary key oid constraint
419 alter table atacc1 add constraint atacc_oid1 primary key(oid);
420 drop table atacc1;
421
422 -- let's do one where the primary key constraint fails when added
423 create table atacc1 ( test int );
424 -- insert soon to be failing rows
425 insert into atacc1 (test) values (2);
426 insert into atacc1 (test) values (2);
427 -- add a primary key (fails)
428 alter table atacc1 add constraint atacc_test1 primary key (test);
429 insert into atacc1 (test) values (3);
430 drop table atacc1;
431
432 -- let's do another one where the primary key constraint fails when added
433 create table atacc1 ( test int );
434 -- insert soon to be failing row
435 insert into atacc1 (test) values (NULL);
436 -- add a primary key (fails)
437 alter table atacc1 add constraint atacc_test1 primary key (test);
438 insert into atacc1 (test) values (3);
439 drop table atacc1;
440
441 -- let's do one where the primary key constraint fails
442 -- because the column doesn't exist
443 create table atacc1 ( test int );
444 -- add a primary key constraint (fails)
445 alter table atacc1 add constraint atacc_test1 primary key (test1);
446 drop table atacc1;
447
448 -- something a little more complicated
449 create table atacc1 ( test int, test2 int);
450 -- add a primary key constraint
451 alter table atacc1 add constraint atacc_test1 primary key (test, test2);
452 -- try adding a second primary key - should fail
453 alter table atacc1 add constraint atacc_test2 primary key (test);
454 -- insert initial value
455 insert into atacc1 (test,test2) values (4,4);
456 -- should fail
457 insert into atacc1 (test,test2) values (4,4);
458 insert into atacc1 (test,test2) values (NULL,3);
459 insert into atacc1 (test,test2) values (3, NULL);
460 insert into atacc1 (test,test2) values (NULL,NULL);
461 -- should all succeed
462 insert into atacc1 (test,test2) values (4,5);
463 insert into atacc1 (test,test2) values (5,4);
464 insert into atacc1 (test,test2) values (5,5);
465 drop table atacc1;
466
467 -- lets do some naming tests
468 create table atacc1 (test int, test2 int, primary key(test));
469 -- only first should succeed
470 insert into atacc1 (test2, test) values (3, 3);
471 insert into atacc1 (test2, test) values (2, 3);
472 insert into atacc1 (test2, test) values (1, NULL);
473 drop table atacc1;
474
475 -- alter table / alter column [set/drop] not null tests
476 -- try altering system catalogs, should fail
477 alter table pg_class alter column relname drop not null;
478 alter table pg_class alter relname set not null;
479
480 -- try altering non-existent table, should fail
481 alter table non_existent alter column bar set not null;
482 alter table non_existent alter column bar drop not null;
483
484 -- test setting columns to null and not null and vice versa
485 -- test checking for null values and primary key
486 create table atacc1 (test int not null);
487 alter table atacc1 add constraint "atacc1_pkey" primary key (test);
488 alter table atacc1 alter column test drop not null;
489 alter table atacc1 drop constraint "atacc1_pkey";
490 alter table atacc1 alter column test drop not null;
491 insert into atacc1 values (null);
492 alter table atacc1 alter test set not null;
493 delete from atacc1;
494 alter table atacc1 alter test set not null;
495
496 -- try altering a non-existent column, should fail
497 alter table atacc1 alter bar set not null;
498 alter table atacc1 alter bar drop not null;
499
500 -- try altering the oid column, should fail
501 alter table atacc1 alter oid set not null;
502 alter table atacc1 alter oid drop not null;
503
504 -- try creating a view and altering that, should fail
505 create view myview as select * from atacc1;
506 alter table myview alter column test drop not null;
507 alter table myview alter column test set not null;
508 drop view myview;
509
510 drop table atacc1;
511
512 -- test inheritance
513 create table parent (a int);
514 create table child (b varchar(255)) inherits (parent);
515
516 alter table parent alter a set not null;
517 insert into parent values (NULL);
518 insert into child (a, b) values (NULL, 'foo');
519 alter table parent alter a drop not null;
520 insert into parent values (NULL);
521 insert into child (a, b) values (NULL, 'foo');
522 alter table only parent alter a set not null;
523 alter table child alter a set not null;
524 delete from parent;
525 alter table only parent alter a set not null;
526 insert into parent values (NULL);
527 alter table child alter a set not null;
528 insert into child (a, b) values (NULL, 'foo');
529 delete from child;
530 alter table child alter a set not null;
531 insert into child (a, b) values (NULL, 'foo');
532 drop table child;
533 drop table parent;
534
535 -- test setting and removing default values
536 create table def_test (
537         c1      int4 default 5,
538         c2      text default 'initial_default'
539 );
540 insert into def_test default values;
541 alter table def_test alter column c1 drop default;
542 insert into def_test default values;
543 alter table def_test alter column c2 drop default;
544 insert into def_test default values;
545 alter table def_test alter column c1 set default 10;
546 alter table def_test alter column c2 set default 'new_default';
547 insert into def_test default values;
548 select * from def_test;
549
550 -- set defaults to an incorrect type: this should fail
551 alter table def_test alter column c1 set default 'wrong_datatype';
552 alter table def_test alter column c2 set default 20;
553
554 -- set defaults on a non-existent column: this should fail
555 alter table def_test alter column c3 set default 30;
556
557 -- set defaults on views: we need to create a view, add a rule
558 -- to allow insertions into it, and then alter the view to add
559 -- a default
560 create view def_view_test as select * from def_test;
561 create rule def_view_test_ins as
562         on insert to def_view_test
563         do instead insert into def_test select new.*;
564 insert into def_view_test default values;
565 alter table def_view_test alter column c1 set default 45;
566 insert into def_view_test default values;
567 alter table def_view_test alter column c2 set default 'view_default';
568 insert into def_view_test default values;
569 select * from def_view_test;
570
571 drop rule def_view_test_ins on def_view_test;
572 drop view def_view_test;
573 drop table def_test;
574
575 -- alter table / drop column tests
576 -- try altering system catalogs, should fail
577 alter table pg_class drop column relname;
578
579 -- try altering non-existent table, should fail
580 alter table foo drop column bar;
581
582 -- test dropping columns
583 create table atacc1 (a int4 not null, b int4, c int4 not null, d int4);
584 insert into atacc1 values (1, 2, 3, 4);
585 alter table atacc1 drop a;
586 alter table atacc1 drop a;
587
588 -- SELECTs
589 select * from atacc1;
590 select * from atacc1 order by a;
591 select * from atacc1 order by "........pg.dropped.1........";
592 select * from atacc1 group by a;
593 select * from atacc1 group by "........pg.dropped.1........";
594 select atacc1.* from atacc1;
595 select a from atacc1;
596 select atacc1.a from atacc1;
597 select b,c,d from atacc1;
598 select a,b,c,d from atacc1;
599 select * from atacc1 where a = 1;
600 select "........pg.dropped.1........" from atacc1;
601 select atacc1."........pg.dropped.1........" from atacc1;
602 select "........pg.dropped.1........",b,c,d from atacc1;
603 select * from atacc1 where "........pg.dropped.1........" = 1;
604
605 -- UPDATEs
606 update atacc1 set a = 3;
607 update atacc1 set b = 2 where a = 3;
608 update atacc1 set "........pg.dropped.1........" = 3;
609 update atacc1 set b = 2 where "........pg.dropped.1........" = 3;
610
611 -- INSERTs
612 insert into atacc1 values (10, 11, 12, 13);
613 insert into atacc1 values (default, 11, 12, 13);
614 insert into atacc1 values (11, 12, 13);
615 insert into atacc1 (a) values (10);
616 insert into atacc1 (a) values (default);
617 insert into atacc1 (a,b,c,d) values (10,11,12,13);
618 insert into atacc1 (a,b,c,d) values (default,11,12,13);
619 insert into atacc1 (b,c,d) values (11,12,13);
620 insert into atacc1 ("........pg.dropped.1........") values (10);
621 insert into atacc1 ("........pg.dropped.1........") values (default);
622 insert into atacc1 ("........pg.dropped.1........",b,c,d) values (10,11,12,13);
623 insert into atacc1 ("........pg.dropped.1........",b,c,d) values (default,11,12,13);
624
625 -- DELETEs
626 delete from atacc1 where a = 3;
627 delete from atacc1 where "........pg.dropped.1........" = 3;
628 delete from atacc1;
629
630 -- try dropping a non-existent column, should fail
631 alter table atacc1 drop bar;
632
633 -- try dropping the oid column, should fail
634 alter table atacc1 drop oid;
635
636 -- try creating a view and altering that, should fail
637 create view myview as select * from atacc1;
638 select * from myview;
639 alter table myview drop d;
640 drop view myview;
641
642 -- test some commands to make sure they fail on the dropped column
643 analyze atacc1(a);
644 analyze atacc1("........pg.dropped.1........");
645 vacuum analyze atacc1(a);
646 vacuum analyze atacc1("........pg.dropped.1........");
647 comment on column atacc1.a is 'testing';
648 comment on column atacc1."........pg.dropped.1........" is 'testing';
649 alter table atacc1 alter a set storage plain;
650 alter table atacc1 alter "........pg.dropped.1........" set storage plain;
651 alter table atacc1 alter a set statistics 0;
652 alter table atacc1 alter "........pg.dropped.1........" set statistics 0;
653 alter table atacc1 alter a set default 3;
654 alter table atacc1 alter "........pg.dropped.1........" set default 3;
655 alter table atacc1 alter a drop default;
656 alter table atacc1 alter "........pg.dropped.1........" drop default;
657 alter table atacc1 alter a set not null;
658 alter table atacc1 alter "........pg.dropped.1........" set not null;
659 alter table atacc1 alter a drop not null;
660 alter table atacc1 alter "........pg.dropped.1........" drop not null;
661 alter table atacc1 rename a to x;
662 alter table atacc1 rename "........pg.dropped.1........" to x;
663 alter table atacc1 add primary key(a);
664 alter table atacc1 add primary key("........pg.dropped.1........");
665 alter table atacc1 add unique(a);
666 alter table atacc1 add unique("........pg.dropped.1........");
667 alter table atacc1 add check (a > 3);
668 alter table atacc1 add check ("........pg.dropped.1........" > 3);
669 create table atacc2 (id int4 unique);
670 alter table atacc1 add foreign key (a) references atacc2(id);
671 alter table atacc1 add foreign key ("........pg.dropped.1........") references atacc2(id);
672 alter table atacc2 add foreign key (id) references atacc1(a);
673 alter table atacc2 add foreign key (id) references atacc1("........pg.dropped.1........");
674 drop table atacc2;
675 create index "testing_idx" on atacc1(a);
676 create index "testing_idx" on atacc1("........pg.dropped.1........");
677
678 -- test create as and select into
679 insert into atacc1 values (21, 22, 23);
680 create table test1 as select * from atacc1;
681 select * from test1;
682 drop table test1;
683 select * into test2 from atacc1;
684 select * from test2;
685 drop table test2;
686
687 -- try dropping all columns
688 alter table atacc1 drop c;
689 alter table atacc1 drop d;
690 alter table atacc1 drop b;
691 select * from atacc1;
692
693 drop table atacc1;
694
695 -- test inheritance
696 create table parent (a int, b int, c int);
697 insert into parent values (1, 2, 3);
698 alter table parent drop a;
699 create table child (d varchar(255)) inherits (parent);
700 insert into child values (12, 13, 'testing');
701
702 select * from parent;
703 select * from child;
704 alter table parent drop c;
705 select * from parent;
706 select * from child;
707
708 drop table child;
709 drop table parent;
710
711 -- test copy in/out
712 create table test (a int4, b int4, c int4);
713 insert into test values (1,2,3);
714 alter table test drop a;
715 copy test to stdout;
716 copy test(a) to stdout;
717 copy test("........pg.dropped.1........") to stdout;
718 copy test from stdin;
719 10      11      12
720 \.
721 select * from test;
722 copy test from stdin;
723 21      22
724 \.
725 select * from test;
726 copy test(a) from stdin;
727 copy test("........pg.dropped.1........") from stdin;
728 copy test(b,c) from stdin;
729 31      32
730 \.
731 select * from test;
732 drop table test;
733