]> granicus.if.org Git - postgresql/blob - src/test/regress/expected/alter_table.out
This patch fixes in intermittent failure in the regression tests:
[postgresql] / src / test / regress / expected / alter_table.out
1 --
2 -- ALTER_TABLE
3 -- add attribute
4 --
5 CREATE TABLE tmp (initial int4);
6 ALTER TABLE tmp ADD COLUMN a int4;
7 ALTER TABLE tmp ADD COLUMN b name;
8 ALTER TABLE tmp ADD COLUMN c text;
9 ALTER TABLE tmp ADD COLUMN d float8;
10 ALTER TABLE tmp ADD COLUMN e float4;
11 ALTER TABLE tmp ADD COLUMN f int2;
12 ALTER TABLE tmp ADD COLUMN g polygon;
13 ALTER TABLE tmp ADD COLUMN h abstime;
14 ALTER TABLE tmp ADD COLUMN i char;
15 ALTER TABLE tmp ADD COLUMN j abstime[];
16 ALTER TABLE tmp ADD COLUMN k int4;
17 ALTER TABLE tmp ADD COLUMN l tid;
18 ALTER TABLE tmp ADD COLUMN m xid;
19 ALTER TABLE tmp ADD COLUMN n oidvector;
20 --ALTER TABLE tmp ADD COLUMN o lock;
21 ALTER TABLE tmp ADD COLUMN p smgr;
22 ALTER TABLE tmp ADD COLUMN q point;
23 ALTER TABLE tmp ADD COLUMN r lseg;
24 ALTER TABLE tmp ADD COLUMN s path;
25 ALTER TABLE tmp ADD COLUMN t box;
26 ALTER TABLE tmp ADD COLUMN u tinterval;
27 ALTER TABLE tmp ADD COLUMN v timestamp;
28 ALTER TABLE tmp ADD COLUMN w interval;
29 ALTER TABLE tmp ADD COLUMN x float8[];
30 ALTER TABLE tmp ADD COLUMN y float4[];
31 ALTER TABLE tmp ADD COLUMN z int2[];
32 INSERT INTO tmp (a, b, c, d, e, f, g, h, i, j, k, l, m, n, p, q, r, s, t, u,
33         v, w, x, y, z)
34    VALUES (4, 'name', 'text', 4.1, 4.1, 2, '(4.1,4.1,3.1,3.1)', 
35         'Mon May  1 00:30:30 1995', 'c', '{Mon May  1 00:30:30 1995, Monday Aug 24 14:43:07 1992, epoch}', 
36         314159, '(1,1)', '512',
37         '1 2 3 4 5 6 7 8', 'magnetic disk', '(1.1,1.1)', '(4.1,4.1,3.1,3.1)',
38         '(0,2,4.1,4.1,3.1,3.1)', '(4.1,4.1,3.1,3.1)', '["epoch" "infinity"]',
39         'epoch', '01:00:10', '{1.0,2.0,3.0,4.0}', '{1.0,2.0,3.0,4.0}', '{1,2,3,4}');
40 SELECT * FROM tmp;
41  initial | a |  b   |  c   |  d  |  e  | f |           g           |              h               | i |                                               j                                                |   k    |   l   |  m  |        n        |       p       |     q     |           r           |              s              |          t          |                      u                      |            v             |        w         |     x     |     y     |     z     
42 ---------+---+------+------+-----+-----+---+-----------------------+------------------------------+---+------------------------------------------------------------------------------------------------+--------+-------+-----+-----------------+---------------+-----------+-----------------------+-----------------------------+---------------------+---------------------------------------------+--------------------------+------------------+-----------+-----------+-----------
43          | 4 | name | text | 4.1 | 4.1 | 2 | ((4.1,4.1),(3.1,3.1)) | Mon May 01 00:30:30 1995 PDT | c | {"Mon May 01 00:30:30 1995 PDT","Mon Aug 24 14:43:07 1992 PDT","Wed Dec 31 16:00:00 1969 PST"} | 314159 | (1,1) | 512 | 1 2 3 4 5 6 7 8 | magnetic disk | (1.1,1.1) | [(4.1,4.1),(3.1,3.1)] | ((0,2),(4.1,4.1),(3.1,3.1)) | (4.1,4.1),(3.1,3.1) | ["Wed Dec 31 16:00:00 1969 PST" "infinity"] | Thu Jan 01 00:00:00 1970 | @ 1 hour 10 secs | {1,2,3,4} | {1,2,3,4} | {1,2,3,4}
44 (1 row)
45
46 DROP TABLE tmp;
47 -- the wolf bug - schema mods caused inconsistent row descriptors 
48 CREATE TABLE tmp (
49         initial         int4
50 );
51 ALTER TABLE tmp ADD COLUMN a int4;
52 ALTER TABLE tmp ADD COLUMN b name;
53 ALTER TABLE tmp ADD COLUMN c text;
54 ALTER TABLE tmp ADD COLUMN d float8;
55 ALTER TABLE tmp ADD COLUMN e float4;
56 ALTER TABLE tmp ADD COLUMN f int2;
57 ALTER TABLE tmp ADD COLUMN g polygon;
58 ALTER TABLE tmp ADD COLUMN h abstime;
59 ALTER TABLE tmp ADD COLUMN i char;
60 ALTER TABLE tmp ADD COLUMN j abstime[];
61 ALTER TABLE tmp ADD COLUMN k int4;
62 ALTER TABLE tmp ADD COLUMN l tid;
63 ALTER TABLE tmp ADD COLUMN m xid;
64 ALTER TABLE tmp ADD COLUMN n oidvector;
65 --ALTER TABLE tmp ADD COLUMN o lock;
66 ALTER TABLE tmp ADD COLUMN p smgr;
67 ALTER TABLE tmp ADD COLUMN q point;
68 ALTER TABLE tmp ADD COLUMN r lseg;
69 ALTER TABLE tmp ADD COLUMN s path;
70 ALTER TABLE tmp ADD COLUMN t box;
71 ALTER TABLE tmp ADD COLUMN u tinterval;
72 ALTER TABLE tmp ADD COLUMN v timestamp;
73 ALTER TABLE tmp ADD COLUMN w interval;
74 ALTER TABLE tmp ADD COLUMN x float8[];
75 ALTER TABLE tmp ADD COLUMN y float4[];
76 ALTER TABLE tmp ADD COLUMN z int2[];
77 INSERT INTO tmp (a, b, c, d, e, f, g, h, i, j, k, l, m, n, p, q, r, s, t, u,
78         v, w, x, y, z)
79    VALUES (4, 'name', 'text', 4.1, 4.1, 2, '(4.1,4.1,3.1,3.1)', 
80         'Mon May  1 00:30:30 1995', 'c', '{Mon May  1 00:30:30 1995, Monday Aug 24 14:43:07 1992, epoch}', 
81         314159, '(1,1)', '512',
82         '1 2 3 4 5 6 7 8', 'magnetic disk', '(1.1,1.1)', '(4.1,4.1,3.1,3.1)',
83         '(0,2,4.1,4.1,3.1,3.1)', '(4.1,4.1,3.1,3.1)', '["epoch" "infinity"]',
84         'epoch', '01:00:10', '{1.0,2.0,3.0,4.0}', '{1.0,2.0,3.0,4.0}', '{1,2,3,4}');
85 SELECT * FROM tmp;
86  initial | a |  b   |  c   |  d  |  e  | f |           g           |              h               | i |                                               j                                                |   k    |   l   |  m  |        n        |       p       |     q     |           r           |              s              |          t          |                      u                      |            v             |        w         |     x     |     y     |     z     
87 ---------+---+------+------+-----+-----+---+-----------------------+------------------------------+---+------------------------------------------------------------------------------------------------+--------+-------+-----+-----------------+---------------+-----------+-----------------------+-----------------------------+---------------------+---------------------------------------------+--------------------------+------------------+-----------+-----------+-----------
88          | 4 | name | text | 4.1 | 4.1 | 2 | ((4.1,4.1),(3.1,3.1)) | Mon May 01 00:30:30 1995 PDT | c | {"Mon May 01 00:30:30 1995 PDT","Mon Aug 24 14:43:07 1992 PDT","Wed Dec 31 16:00:00 1969 PST"} | 314159 | (1,1) | 512 | 1 2 3 4 5 6 7 8 | magnetic disk | (1.1,1.1) | [(4.1,4.1),(3.1,3.1)] | ((0,2),(4.1,4.1),(3.1,3.1)) | (4.1,4.1),(3.1,3.1) | ["Wed Dec 31 16:00:00 1969 PST" "infinity"] | Thu Jan 01 00:00:00 1970 | @ 1 hour 10 secs | {1,2,3,4} | {1,2,3,4} | {1,2,3,4}
89 (1 row)
90
91 DROP TABLE tmp;
92 --
93 -- rename -
94 --   should preserve indices, which we can check by seeing if a SELECT
95 --   chooses an indexscan; however, in the absence of vacuum statistics
96 --   it might not.  Therefore, vacuum first.
97 --
98 VACUUM ANALYZE tenk1;
99 ALTER TABLE tenk1 RENAME TO ten_k;
100 -- 20 values, sorted 
101 SELECT unique1 FROM ten_k WHERE unique1 < 20;
102  unique1 
103 ---------
104        0
105        1
106        2
107        3
108        4
109        5
110        6
111        7
112        8
113        9
114       10
115       11
116       12
117       13
118       14
119       15
120       16
121       17
122       18
123       19
124 (20 rows)
125
126 -- 20 values, sorted 
127 SELECT unique2 FROM ten_k WHERE unique2 < 20;
128  unique2 
129 ---------
130        0
131        1
132        2
133        3
134        4
135        5
136        6
137        7
138        8
139        9
140       10
141       11
142       12
143       13
144       14
145       15
146       16
147       17
148       18
149       19
150 (20 rows)
151
152 -- 100 values, sorted 
153 SELECT hundred FROM ten_k WHERE hundred = 50;
154  hundred 
155 ---------
156       50
157       50
158       50
159       50
160       50
161       50
162       50
163       50
164       50
165       50
166       50
167       50
168       50
169       50
170       50
171       50
172       50
173       50
174       50
175       50
176       50
177       50
178       50
179       50
180       50
181       50
182       50
183       50
184       50
185       50
186       50
187       50
188       50
189       50
190       50
191       50
192       50
193       50
194       50
195       50
196       50
197       50
198       50
199       50
200       50
201       50
202       50
203       50
204       50
205       50
206       50
207       50
208       50
209       50
210       50
211       50
212       50
213       50
214       50
215       50
216       50
217       50
218       50
219       50
220       50
221       50
222       50
223       50
224       50
225       50
226       50
227       50
228       50
229       50
230       50
231       50
232       50
233       50
234       50
235       50
236       50
237       50
238       50
239       50
240       50
241       50
242       50
243       50
244       50
245       50
246       50
247       50
248       50
249       50
250       50
251       50
252       50
253       50
254       50
255       50
256 (100 rows)
257
258 ALTER TABLE ten_k RENAME TO tenk1;
259 -- 5 values, sorted 
260 SELECT unique1 FROM tenk1 WHERE unique1 < 5;
261  unique1 
262 ---------
263        0
264        1
265        2
266        3
267        4
268 (5 rows)
269
270 -- ALTER TABLE ... RENAME on non-table relations
271 -- renaming indexes (FIXME: this should probably test the index's functionality)
272 ALTER TABLE onek_unique1 RENAME TO tmp_onek_unique1;
273 ALTER TABLE tmp_onek_unique1 RENAME TO onek_unique1;
274 -- renaming views
275 CREATE VIEW tmp_view (unique1) AS SELECT unique1 FROM tenk1;
276 ALTER TABLE tmp_view RENAME TO tmp_view_new;
277 -- 5 values, sorted 
278 SELECT unique1 FROM tenk1 WHERE unique1 < 5;
279  unique1 
280 ---------
281        0
282        1
283        2
284        3
285        4
286 (5 rows)
287
288 DROP VIEW tmp_view_new;
289 -- renaming sequences
290 CREATE SEQUENCE foo_seq;
291 ALTER TABLE foo_seq RENAME TO foo_seq_new;
292 SELECT * FROM foo_seq_new;
293  sequence_name | last_value | increment_by |      max_value      | min_value | cache_value | log_cnt | is_cycled | is_called 
294 ---------------+------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
295  foo_seq       |          1 |            1 | 9223372036854775807 |         1 |           1 |       1 | f         | f
296 (1 row)
297
298 DROP SEQUENCE foo_seq_new;
299 -- toast-like relation name
300 alter table stud_emp rename to pg_toast_stud_emp;
301 alter table pg_toast_stud_emp rename to stud_emp;
302 -- FOREIGN KEY CONSTRAINT adding TEST
303 CREATE TABLE tmp2 (a int primary key);
304 NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 'tmp2_pkey' for table 'tmp2'
305 CREATE TABLE tmp3 (a int, b int);
306 CREATE TABLE tmp4 (a int, b int, unique(a,b));
307 NOTICE:  CREATE TABLE / UNIQUE will create implicit index 'tmp4_a_key' for table 'tmp4'
308 CREATE TABLE tmp5 (a int, b int);
309 -- Insert rows into tmp2 (pktable)
310 INSERT INTO tmp2 values (1);
311 INSERT INTO tmp2 values (2);
312 INSERT INTO tmp2 values (3);
313 INSERT INTO tmp2 values (4);
314 -- Insert rows into tmp3
315 INSERT INTO tmp3 values (1,10);
316 INSERT INTO tmp3 values (1,20);
317 INSERT INTO tmp3 values (5,50);
318 -- Try (and fail) to add constraint due to invalid source columns
319 ALTER TABLE tmp3 add constraint tmpconstr foreign key(c) references tmp2 match full;
320 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
321 ERROR:  ALTER TABLE: column "c" referenced in foreign key constraint does not exist
322 -- Try (and fail) to add constraint due to invalide destination columns explicitly given
323 ALTER TABLE tmp3 add constraint tmpconstr foreign key(a) references tmp2(b) match full;
324 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
325 ERROR:  UNIQUE constraint matching given keys for referenced table "tmp2" not found
326 -- Try (and fail) to add constraint due to invalid data
327 ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
328 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
329 ERROR:  tmpconstr referential integrity violation - key referenced from tmp3 not found in tmp2
330 -- Delete failing row
331 DELETE FROM tmp3 where a=5;
332 -- Try (and succeed)
333 ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
334 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
335 -- Try (and fail) to create constraint from tmp5(a) to tmp4(a) - unique constraint on
336 -- tmp4 is a,b
337 ALTER TABLE tmp5 add constraint tmpconstr foreign key(a) references tmp4(a) match full;
338 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
339 ERROR:  UNIQUE constraint matching given keys for referenced table "tmp4" not found
340 DROP TABLE tmp5;
341 DROP TABLE tmp4;
342 DROP TABLE tmp3;
343 DROP TABLE tmp2;
344 -- Foreign key adding test with mixed types
345 -- Note: these tables are TEMP to avoid name conflicts when this test
346 -- is run in parallel with foreign_key.sql.
347 CREATE TEMP TABLE PKTABLE (ptest1 int PRIMARY KEY);
348 NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 'pktable_pkey' for table 'pktable'
349 CREATE TEMP TABLE FKTABLE (ftest1 inet);
350 -- This next should fail, because inet=int does not exist
351 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable;
352 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
353 ERROR:  Unable to identify an operator '=' for types 'inet' and 'integer'
354         You will have to retype this query using an explicit cast
355 -- This should also fail for the same reason, but here we
356 -- give the column name
357 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable(ptest1);
358 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
359 ERROR:  Unable to identify an operator '=' for types 'inet' and 'integer'
360         You will have to retype this query using an explicit cast
361 -- This should succeed, even though they are different types
362 -- because varchar=int does exist
363 DROP TABLE FKTABLE;
364 CREATE TEMP TABLE FKTABLE (ftest1 varchar);
365 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable;
366 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
367 -- As should this
368 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable(ptest1);
369 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
370 DROP TABLE pktable cascade;
371 NOTICE:  Drop cascades to constraint $2 on table fktable
372 NOTICE:  Drop cascades to constraint $1 on table fktable
373 DROP TABLE fktable;
374 CREATE TEMP TABLE PKTABLE (ptest1 int, ptest2 inet,
375                            PRIMARY KEY(ptest1, ptest2));
376 NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 'pktable_pkey' for table 'pktable'
377 -- This should fail, because we just chose really odd types
378 CREATE TEMP TABLE FKTABLE (ftest1 cidr, ftest2 timestamp);
379 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2) references pktable;
380 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
381 ERROR:  Unable to identify an operator '=' for types 'cidr' and 'integer'
382         You will have to retype this query using an explicit cast
383 DROP TABLE FKTABLE;
384 -- Again, so should this...
385 CREATE TEMP TABLE FKTABLE (ftest1 cidr, ftest2 timestamp);
386 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2)
387      references pktable(ptest1, ptest2);
388 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
389 ERROR:  Unable to identify an operator '=' for types 'cidr' and 'integer'
390         You will have to retype this query using an explicit cast
391 DROP TABLE FKTABLE;
392 -- This fails because we mixed up the column ordering
393 CREATE TEMP TABLE FKTABLE (ftest1 int, ftest2 inet);
394 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2)
395      references pktable(ptest2, ptest1);
396 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
397 ERROR:  Unable to identify an operator '=' for types 'integer' and 'inet'
398         You will have to retype this query using an explicit cast
399 -- As does this...
400 ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest2, ftest1)
401      references pktable(ptest1, ptest2);
402 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
403 ERROR:  Unable to identify an operator '=' for types 'inet' and 'integer'
404         You will have to retype this query using an explicit cast
405 -- temp tables should go away by themselves, need not drop them.
406 -- test check constraint adding
407 create table atacc1 ( test int );
408 -- add a check constraint
409 alter table atacc1 add constraint atacc_test1 check (test>3);
410 -- should fail
411 insert into atacc1 (test) values (2);
412 ERROR:  ExecInsert: rejected due to CHECK constraint atacc_test1
413 -- should succeed
414 insert into atacc1 (test) values (4);
415 drop table atacc1;
416 -- let's do one where the check fails when added
417 create table atacc1 ( test int );
418 -- insert a soon to be failing row
419 insert into atacc1 (test) values (2);
420 -- add a check constraint (fails)
421 alter table atacc1 add constraint atacc_test1 check (test>3);
422 ERROR:  AlterTableAddConstraint: rejected due to CHECK constraint atacc_test1
423 insert into atacc1 (test) values (4);
424 drop table atacc1;
425 -- let's do one where the check fails because the column doesn't exist
426 create table atacc1 ( test int );
427 -- add a check constraint (fails)
428 alter table atacc1 add constraint atacc_test1 check (test1>3);
429 ERROR:  Attribute "test1" not found
430 drop table atacc1;
431 -- something a little more complicated
432 create table atacc1 ( test int, test2 int, test3 int);
433 -- add a check constraint (fails)
434 alter table atacc1 add constraint atacc_test1 check (test+test2<test3*4);
435 -- should fail
436 insert into atacc1 (test,test2,test3) values (4,4,2);
437 ERROR:  ExecInsert: rejected due to CHECK constraint atacc_test1
438 -- should succeed
439 insert into atacc1 (test,test2,test3) values (4,4,5);
440 drop table atacc1;
441 -- lets do some naming tests
442 create table atacc1 (test int check (test>3), test2 int);
443 alter table atacc1 add check (test2>test);
444 -- should fail for $2
445 insert into atacc1 (test2, test) values (3, 4);
446 ERROR:  ExecInsert: rejected due to CHECK constraint $1
447 drop table atacc1;
448 -- inheritance related tests
449 create table atacc1 (test int);
450 create table atacc2 (test2 int);
451 create table atacc3 (test3 int) inherits (atacc1, atacc2);
452 alter table atacc2 add constraint foo check (test2>0);
453 -- fail and then succeed on atacc2
454 insert into atacc2 (test2) values (-3);
455 ERROR:  ExecInsert: rejected due to CHECK constraint foo
456 insert into atacc2 (test2) values (3);
457 -- fail and then succeed on atacc3
458 insert into atacc3 (test2) values (-3);
459 ERROR:  ExecInsert: rejected due to CHECK constraint foo
460 insert into atacc3 (test2) values (3);
461 drop table atacc3;
462 drop table atacc2;
463 drop table atacc1;
464 -- let's try only to add only to the parent
465 create table atacc1 (test int);
466 create table atacc2 (test2 int);
467 create table atacc3 (test3 int) inherits (atacc1, atacc2);
468 alter table only atacc2 add constraint foo check (test2>0);
469 -- fail and then succeed on atacc2
470 insert into atacc2 (test2) values (-3);
471 ERROR:  ExecInsert: rejected due to CHECK constraint foo
472 insert into atacc2 (test2) values (3);
473 -- both succeed on atacc3
474 insert into atacc3 (test2) values (-3);
475 insert into atacc3 (test2) values (3);
476 drop table atacc3;
477 drop table atacc2;
478 drop table atacc1;
479 -- test unique constraint adding
480 create table atacc1 ( test int );
481 -- add a unique constraint
482 alter table atacc1 add constraint atacc_test1 unique (test);
483 NOTICE:  ALTER TABLE / ADD UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
484 -- insert first value
485 insert into atacc1 (test) values (2);
486 -- should fail
487 insert into atacc1 (test) values (2);
488 ERROR:  Cannot insert a duplicate key into unique index atacc_test1
489 -- should succeed
490 insert into atacc1 (test) values (4);
491 -- try adding a unique oid constraint
492 alter table atacc1 add constraint atacc_oid1 unique(oid);
493 NOTICE:  ALTER TABLE / ADD UNIQUE will create implicit index 'atacc_oid1' for table 'atacc1'
494 drop table atacc1;
495 -- let's do one where the unique constraint fails when added
496 create table atacc1 ( test int );
497 -- insert soon to be failing rows
498 insert into atacc1 (test) values (2);
499 insert into atacc1 (test) values (2);
500 -- add a unique constraint (fails)
501 alter table atacc1 add constraint atacc_test1 unique (test);
502 NOTICE:  ALTER TABLE / ADD UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
503 ERROR:  Cannot create unique index. Table contains non-unique values
504 insert into atacc1 (test) values (3);
505 drop table atacc1;
506 -- let's do one where the unique constraint fails
507 -- because the column doesn't exist
508 create table atacc1 ( test int );
509 -- add a unique constraint (fails)
510 alter table atacc1 add constraint atacc_test1 unique (test1);
511 ERROR:  ALTER TABLE: column "test1" named in key does not exist
512 drop table atacc1;
513 -- something a little more complicated
514 create table atacc1 ( test int, test2 int);
515 -- add a unique constraint
516 alter table atacc1 add constraint atacc_test1 unique (test, test2);
517 NOTICE:  ALTER TABLE / ADD UNIQUE will create implicit index 'atacc_test1' for table 'atacc1'
518 -- insert initial value
519 insert into atacc1 (test,test2) values (4,4);
520 -- should fail
521 insert into atacc1 (test,test2) values (4,4);
522 ERROR:  Cannot insert a duplicate key into unique index atacc_test1
523 -- should all succeed
524 insert into atacc1 (test,test2) values (4,5);
525 insert into atacc1 (test,test2) values (5,4);
526 insert into atacc1 (test,test2) values (5,5);
527 drop table atacc1;
528 -- lets do some naming tests
529 create table atacc1 (test int, test2 int, unique(test));
530 NOTICE:  CREATE TABLE / UNIQUE will create implicit index 'atacc1_test_key' for table 'atacc1'
531 alter table atacc1 add unique (test2);
532 NOTICE:  ALTER TABLE / ADD UNIQUE will create implicit index 'atacc1_test2_key' for table 'atacc1'
533 -- should fail for @@ second one @@
534 insert into atacc1 (test2, test) values (3, 3);
535 insert into atacc1 (test2, test) values (2, 3);
536 ERROR:  Cannot insert a duplicate key into unique index atacc1_test_key
537 drop table atacc1;
538 -- test primary key constraint adding
539 create table atacc1 ( test int );
540 -- add a primary key constraint
541 alter table atacc1 add constraint atacc_test1 primary key (test);
542 ERROR:  Existing attribute "test" cannot be a PRIMARY KEY because it is not marked NOT NULL
543 -- insert first value
544 insert into atacc1 (test) values (2);
545 -- should fail
546 insert into atacc1 (test) values (2);
547 -- should succeed
548 insert into atacc1 (test) values (4);
549 -- inserting NULL should fail
550 insert into atacc1 (test) values(NULL);
551 -- try adding a primary key oid constraint
552 alter table atacc1 add constraint atacc_oid1 primary key(oid);
553 NOTICE:  ALTER TABLE / ADD PRIMARY KEY will create implicit index 'atacc_oid1' for table 'atacc1'
554 drop table atacc1;
555 -- let's do one where the primary key constraint fails when added
556 create table atacc1 ( test int );
557 -- insert soon to be failing rows
558 insert into atacc1 (test) values (2);
559 insert into atacc1 (test) values (2);
560 -- add a primary key (fails)
561 alter table atacc1 add constraint atacc_test1 primary key (test);
562 ERROR:  Existing attribute "test" cannot be a PRIMARY KEY because it is not marked NOT NULL
563 insert into atacc1 (test) values (3);
564 drop table atacc1;
565 -- let's do another one where the primary key constraint fails when added
566 create table atacc1 ( test int );
567 -- insert soon to be failing row
568 insert into atacc1 (test) values (NULL);
569 -- add a primary key (fails)
570 alter table atacc1 add constraint atacc_test1 primary key (test);
571 ERROR:  Existing attribute "test" cannot be a PRIMARY KEY because it is not marked NOT NULL
572 insert into atacc1 (test) values (3);
573 drop table atacc1;
574 -- let's do one where the primary key constraint fails
575 -- because the column doesn't exist
576 create table atacc1 ( test int );
577 -- add a primary key constraint (fails)
578 alter table atacc1 add constraint atacc_test1 primary key (test1);
579 ERROR:  ALTER TABLE: column "test1" named in key does not exist
580 drop table atacc1;
581 -- something a little more complicated
582 create table atacc1 ( test int, test2 int);
583 -- add a primary key constraint
584 alter table atacc1 add constraint atacc_test1 primary key (test, test2);
585 ERROR:  Existing attribute "test" cannot be a PRIMARY KEY because it is not marked NOT NULL
586 -- try adding a second primary key - should fail
587 alter table atacc1 add constraint atacc_test2 primary key (test);
588 ERROR:  Existing attribute "test" cannot be a PRIMARY KEY because it is not marked NOT NULL
589 -- insert initial value
590 insert into atacc1 (test,test2) values (4,4);
591 -- should fail
592 insert into atacc1 (test,test2) values (4,4);
593 insert into atacc1 (test,test2) values (NULL,3);
594 insert into atacc1 (test,test2) values (3, NULL);
595 insert into atacc1 (test,test2) values (NULL,NULL);
596 -- should all succeed
597 insert into atacc1 (test,test2) values (4,5);
598 insert into atacc1 (test,test2) values (5,4);
599 insert into atacc1 (test,test2) values (5,5);
600 drop table atacc1;
601 -- lets do some naming tests
602 create table atacc1 (test int, test2 int, primary key(test));
603 NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 'atacc1_pkey' for table 'atacc1'
604 -- only first should succeed
605 insert into atacc1 (test2, test) values (3, 3);
606 insert into atacc1 (test2, test) values (2, 3);
607 ERROR:  Cannot insert a duplicate key into unique index atacc1_pkey
608 insert into atacc1 (test2, test) values (1, NULL);
609 ERROR:  ExecInsert: Fail to add null value in not null attribute test
610 drop table atacc1;
611 -- alter table / alter column [set/drop] not null tests
612 -- try altering system catalogs, should fail
613 alter table pg_class alter column relname drop not null;
614 ERROR:  ALTER TABLE: relation "pg_class" is a system catalog
615 alter table pg_class alter relname set not null;
616 ERROR:  ALTER TABLE: relation "pg_class" is a system catalog
617 -- try altering non-existent table, should fail
618 alter table non_existent alter column bar set not null;
619 ERROR:  Relation "non_existent" does not exist
620 alter table non_existent alter column bar drop not null;
621 ERROR:  Relation "non_existent" does not exist
622 -- test setting columns to null and not null and vice versa
623 -- test checking for null values and primary key
624 create table atacc1 (test int not null);
625 alter table atacc1 add constraint "atacc1_pkey" primary key (test);
626 NOTICE:  ALTER TABLE / ADD PRIMARY KEY will create implicit index 'atacc1_pkey' for table 'atacc1'
627 alter table atacc1 alter column test drop not null;
628 ERROR:  ALTER TABLE: Attribute "test" is in a primary key
629 alter table atacc1 drop constraint "atacc1_pkey";
630 alter table atacc1 alter column test drop not null;
631 insert into atacc1 values (null);
632 alter table atacc1 alter test set not null;
633 ERROR:  ALTER TABLE: Attribute "test" contains NULL values
634 delete from atacc1;
635 alter table atacc1 alter test set not null;
636 -- try altering a non-existent column, should fail
637 alter table atacc1 alter bar set not null;
638 ERROR:  Relation "atacc1" has no column "bar"
639 alter table atacc1 alter bar drop not null;
640 ERROR:  Relation "atacc1" has no column "bar"
641 -- try altering the oid column, should fail
642 alter table atacc1 alter oid set not null;
643 ERROR:  ALTER TABLE: Cannot alter system attribute "oid"
644 alter table atacc1 alter oid drop not null;
645 ERROR:  ALTER TABLE: Cannot alter system attribute "oid"
646 -- try creating a view and altering that, should fail
647 create view myview as select * from atacc1;
648 alter table myview alter column test drop not null;
649 ERROR:  ALTER TABLE: relation "myview" is not a table
650 alter table myview alter column test set not null;
651 ERROR:  ALTER TABLE: relation "myview" is not a table
652 drop view myview;
653 drop table atacc1;
654 -- test inheritance
655 create table parent (a int);
656 create table child (b varchar(255)) inherits (parent);
657 alter table parent alter a set not null;
658 insert into parent values (NULL);
659 ERROR:  ExecInsert: Fail to add null value in not null attribute a
660 insert into child (a, b) values (NULL, 'foo');
661 ERROR:  ExecInsert: Fail to add null value in not null attribute a
662 alter table parent alter a drop not null;
663 insert into parent values (NULL);
664 insert into child (a, b) values (NULL, 'foo');
665 alter table only parent alter a set not null;
666 ERROR:  ALTER TABLE: Attribute "a" contains NULL values
667 alter table child alter a set not null;
668 ERROR:  ALTER TABLE: Attribute "a" contains NULL values
669 delete from parent;
670 alter table only parent alter a set not null;
671 insert into parent values (NULL);
672 ERROR:  ExecInsert: Fail to add null value in not null attribute a
673 alter table child alter a set not null;
674 insert into child (a, b) values (NULL, 'foo');
675 ERROR:  ExecInsert: Fail to add null value in not null attribute a
676 delete from child;
677 alter table child alter a set not null;
678 insert into child (a, b) values (NULL, 'foo');
679 ERROR:  ExecInsert: Fail to add null value in not null attribute a
680 drop table child;
681 drop table parent;
682 -- test setting and removing default values
683 create table def_test (
684         c1      int4 default 5,
685         c2      text default 'initial_default'
686 );
687 insert into def_test default values;
688 alter table def_test alter column c1 drop default;
689 insert into def_test default values;
690 alter table def_test alter column c2 drop default;
691 insert into def_test default values;
692 alter table def_test alter column c1 set default 10;
693 alter table def_test alter column c2 set default 'new_default';
694 insert into def_test default values;
695 select * from def_test;
696  c1 |       c2        
697 ----+-----------------
698   5 | initial_default
699     | initial_default
700     | 
701  10 | new_default
702 (4 rows)
703
704 -- set defaults to an incorrect type: this should fail
705 alter table def_test alter column c1 set default 'wrong_datatype';
706 ERROR:  pg_atoi: error in "wrong_datatype": can't parse "wrong_datatype"
707 alter table def_test alter column c2 set default 20;
708 -- set defaults on a non-existent column: this should fail
709 alter table def_test alter column c3 set default 30;
710 ERROR:  Relation "def_test" has no column "c3"
711 -- set defaults on views: we need to create a view, add a rule
712 -- to allow insertions into it, and then alter the view to add
713 -- a default
714 create view def_view_test as select * from def_test;
715 create rule def_view_test_ins as
716         on insert to def_view_test
717         do instead insert into def_test select new.*;
718 insert into def_view_test default values;
719 alter table def_view_test alter column c1 set default 45;
720 insert into def_view_test default values;
721 alter table def_view_test alter column c2 set default 'view_default';
722 insert into def_view_test default values;
723 select * from def_view_test;
724  c1 |       c2        
725 ----+-----------------
726   5 | initial_default
727     | initial_default
728     | 
729  10 | new_default
730     | 
731  45 | 
732  45 | view_default
733 (7 rows)
734
735 drop rule def_view_test_ins on def_view_test;
736 drop view def_view_test;
737 drop table def_test;
738 -- alter table / drop column tests
739 -- try altering system catalogs, should fail
740 alter table pg_class drop column relname;
741 ERROR:  ALTER TABLE: relation "pg_class" is a system catalog
742 -- try altering non-existent table, should fail
743 alter table foo drop column bar;
744 ERROR:  Relation "foo" does not exist
745 -- test dropping columns
746 create table atacc1 (a int4 not null, b int4, c int4 not null, d int4);
747 insert into atacc1 values (1, 2, 3, 4);
748 alter table atacc1 drop a;
749 alter table atacc1 drop a;
750 ERROR:  Relation "atacc1" has no column "a"
751 -- SELECTs
752 select * from atacc1;
753  b | c | d 
754 ---+---+---
755  2 | 3 | 4
756 (1 row)
757
758 select * from atacc1 order by a;
759 ERROR:  Attribute "a" not found
760 select * from atacc1 order by "........pg.dropped.1........";
761 ERROR:  Attribute "........pg.dropped.1........" not found
762 select * from atacc1 group by a;
763 ERROR:  Attribute "a" not found
764 select * from atacc1 group by "........pg.dropped.1........";
765 ERROR:  Attribute "........pg.dropped.1........" not found
766 select atacc1.* from atacc1;
767  b | c | d 
768 ---+---+---
769  2 | 3 | 4
770 (1 row)
771
772 select a from atacc1;
773 ERROR:  Attribute "a" not found
774 select atacc1.a from atacc1;
775 ERROR:  No such attribute atacc1.a
776 select b,c,d from atacc1;
777  b | c | d 
778 ---+---+---
779  2 | 3 | 4
780 (1 row)
781
782 select a,b,c,d from atacc1;
783 ERROR:  Attribute "a" not found
784 select * from atacc1 where a = 1;
785 ERROR:  Attribute "a" not found
786 select "........pg.dropped.1........" from atacc1;
787 ERROR:  Attribute "........pg.dropped.1........" not found
788 select atacc1."........pg.dropped.1........" from atacc1;
789 ERROR:  No such attribute atacc1.........pg.dropped.1........
790 select "........pg.dropped.1........",b,c,d from atacc1;
791 ERROR:  Attribute "........pg.dropped.1........" not found
792 select * from atacc1 where "........pg.dropped.1........" = 1;
793 ERROR:  Attribute "........pg.dropped.1........" not found
794 -- UPDATEs
795 update atacc1 set a = 3;
796 ERROR:  Relation "atacc1" has no column "a"
797 update atacc1 set b = 2 where a = 3;
798 ERROR:  Attribute "a" not found
799 update atacc1 set "........pg.dropped.1........" = 3;
800 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
801 update atacc1 set b = 2 where "........pg.dropped.1........" = 3;
802 ERROR:  Attribute "........pg.dropped.1........" not found
803 -- INSERTs
804 insert into atacc1 values (10, 11, 12, 13);
805 ERROR:  INSERT has more expressions than target columns
806 insert into atacc1 values (default, 11, 12, 13);
807 ERROR:  INSERT has more expressions than target columns
808 insert into atacc1 values (11, 12, 13);
809 insert into atacc1 (a) values (10);
810 ERROR:  Relation "atacc1" has no column "a"
811 insert into atacc1 (a) values (default);
812 ERROR:  Relation "atacc1" has no column "a"
813 insert into atacc1 (a,b,c,d) values (10,11,12,13);
814 ERROR:  Relation "atacc1" has no column "a"
815 insert into atacc1 (a,b,c,d) values (default,11,12,13);
816 ERROR:  Relation "atacc1" has no column "a"
817 insert into atacc1 (b,c,d) values (11,12,13);
818 insert into atacc1 ("........pg.dropped.1........") values (10);
819 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
820 insert into atacc1 ("........pg.dropped.1........") values (default);
821 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
822 insert into atacc1 ("........pg.dropped.1........",b,c,d) values (10,11,12,13);
823 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
824 insert into atacc1 ("........pg.dropped.1........",b,c,d) values (default,11,12,13);
825 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
826 -- DELETEs
827 delete from atacc1 where a = 3;
828 ERROR:  Attribute "a" not found
829 delete from atacc1 where "........pg.dropped.1........" = 3;
830 ERROR:  Attribute "........pg.dropped.1........" not found
831 delete from atacc1;
832 -- try dropping a non-existent column, should fail
833 alter table atacc1 drop bar;
834 ERROR:  Relation "atacc1" has no column "bar"
835 -- try dropping the oid column, should fail
836 alter table atacc1 drop oid;
837 ERROR:  ALTER TABLE: Cannot drop system attribute "oid"
838 -- try creating a view and altering that, should fail
839 create view myview as select * from atacc1;
840 select * from myview;
841  b | c | d 
842 ---+---+---
843 (0 rows)
844
845 alter table myview drop d;
846 ERROR:  ALTER TABLE: relation "myview" is not a table
847 drop view myview;
848 -- test some commands to make sure they fail on the dropped column
849 analyze atacc1(a);
850 ERROR:  Relation "atacc1" has no column "a"
851 analyze atacc1("........pg.dropped.1........");
852 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
853 vacuum analyze atacc1(a);
854 ERROR:  Relation "atacc1" has no column "a"
855 vacuum analyze atacc1("........pg.dropped.1........");
856 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
857 comment on column atacc1.a is 'testing';
858 ERROR:  Relation "atacc1" has no column "a"
859 comment on column atacc1."........pg.dropped.1........" is 'testing';
860 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
861 alter table atacc1 alter a set storage plain;
862 ERROR:  ALTER TABLE: relation "atacc1" has no column "a"
863 alter table atacc1 alter "........pg.dropped.1........" set storage plain;
864 ERROR:  ALTER TABLE: relation "atacc1" has no column "........pg.dropped.1........"
865 alter table atacc1 alter a set statistics 0;
866 ERROR:  ALTER TABLE: relation "atacc1" has no column "a"
867 alter table atacc1 alter "........pg.dropped.1........" set statistics 0;
868 ERROR:  ALTER TABLE: relation "atacc1" has no column "........pg.dropped.1........"
869 alter table atacc1 alter a set default 3;
870 ERROR:  Relation "atacc1" has no column "a"
871 alter table atacc1 alter "........pg.dropped.1........" set default 3;
872 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
873 alter table atacc1 alter a drop default;
874 ERROR:  Relation "atacc1" has no column "a"
875 alter table atacc1 alter "........pg.dropped.1........" drop default;
876 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
877 alter table atacc1 alter a set not null;
878 ERROR:  Relation "atacc1" has no column "a"
879 alter table atacc1 alter "........pg.dropped.1........" set not null;
880 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
881 alter table atacc1 alter a drop not null;
882 ERROR:  Relation "atacc1" has no column "a"
883 alter table atacc1 alter "........pg.dropped.1........" drop not null;
884 ERROR:  Relation "atacc1" has no column "........pg.dropped.1........"
885 alter table atacc1 rename a to x;
886 ERROR:  renameatt: attribute "a" does not exist
887 alter table atacc1 rename "........pg.dropped.1........" to x;
888 ERROR:  renameatt: attribute "........pg.dropped.1........" does not exist
889 alter table atacc1 add primary key(a);
890 ERROR:  ALTER TABLE: column "a" named in key does not exist
891 alter table atacc1 add primary key("........pg.dropped.1........");
892 ERROR:  ALTER TABLE: column "........pg.dropped.1........" named in key does not exist
893 alter table atacc1 add unique(a);
894 ERROR:  ALTER TABLE: column "a" named in key does not exist
895 alter table atacc1 add unique("........pg.dropped.1........");
896 ERROR:  ALTER TABLE: column "........pg.dropped.1........" named in key does not exist
897 alter table atacc1 add check (a > 3);
898 ERROR:  Attribute "a" not found
899 alter table atacc1 add check ("........pg.dropped.1........" > 3);
900 ERROR:  Attribute "........pg.dropped.1........" not found
901 create table atacc2 (id int4 unique);
902 NOTICE:  CREATE TABLE / UNIQUE will create implicit index 'atacc2_id_key' for table 'atacc2'
903 alter table atacc1 add foreign key (a) references atacc2(id);
904 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
905 ERROR:  ALTER TABLE: column "a" referenced in foreign key constraint does not exist
906 alter table atacc1 add foreign key ("........pg.dropped.1........") references atacc2(id);
907 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
908 ERROR:  ALTER TABLE: column "........pg.dropped.1........" referenced in foreign key constraint does not exist
909 alter table atacc2 add foreign key (id) references atacc1(a);
910 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
911 ERROR:  UNIQUE constraint matching given keys for referenced table "atacc1" not found
912 alter table atacc2 add foreign key (id) references atacc1("........pg.dropped.1........");
913 NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
914 ERROR:  UNIQUE constraint matching given keys for referenced table "atacc1" not found
915 drop table atacc2;
916 create index "testing_idx" on atacc1(a);
917 ERROR:  DefineIndex: attribute "a" not found
918 create index "testing_idx" on atacc1("........pg.dropped.1........");
919 ERROR:  DefineIndex: attribute "........pg.dropped.1........" not found
920 -- test create as and select into
921 insert into atacc1 values (21, 22, 23);
922 create table test1 as select * from atacc1;
923 select * from test1;
924  b  | c  | d  
925 ----+----+----
926  21 | 22 | 23
927 (1 row)
928
929 drop table test1;
930 select * into test2 from atacc1;
931 select * from test2;
932  b  | c  | d  
933 ----+----+----
934  21 | 22 | 23
935 (1 row)
936
937 drop table test2;
938 -- try dropping all columns
939 alter table atacc1 drop c;
940 alter table atacc1 drop d;
941 alter table atacc1 drop b;
942 ERROR:  ALTER TABLE: Cannot drop last column from table "atacc1"
943 select * from atacc1;
944  b  
945 ----
946  21
947 (1 row)
948
949 drop table atacc1;
950 -- test inheritance
951 create table parent (a int, b int, c int);
952 insert into parent values (1, 2, 3);
953 alter table parent drop a;
954 create table child (d varchar(255)) inherits (parent);
955 insert into child values (12, 13, 'testing');
956 select * from parent;
957  b  | c  
958 ----+----
959   2 |  3
960  12 | 13
961 (2 rows)
962
963 select * from child;
964  b  | c  |    d    
965 ----+----+---------
966  12 | 13 | testing
967 (1 row)
968
969 alter table parent drop c;
970 select * from parent;
971  b  
972 ----
973   2
974  12
975 (2 rows)
976
977 select * from child;
978  b  |    d    
979 ----+---------
980  12 | testing
981 (1 row)
982
983 drop table child;
984 drop table parent;
985 -- test copy in/out
986 create table test (a int4, b int4, c int4);
987 insert into test values (1,2,3);
988 alter table test drop a;
989 copy test to stdout;
990 2       3
991 copy test(a) to stdout;
992 ERROR:  Relation "test" has no column "a"
993 copy test("........pg.dropped.1........") to stdout;
994 ERROR:  Relation "test" has no column "........pg.dropped.1........"
995 copy test from stdin;
996 ERROR:  copy: line 1, Extra data after last expected column
997 lost synchronization with server, resetting connection
998 select * from test;
999  b | c 
1000 ---+---
1001  2 | 3
1002 (1 row)
1003
1004 copy test from stdin;
1005 select * from test;
1006  b  | c  
1007 ----+----
1008   2 |  3
1009  21 | 22
1010 (2 rows)
1011
1012 copy test(a) from stdin;
1013 ERROR:  Relation "test" has no column "a"
1014 copy test("........pg.dropped.1........") from stdin;
1015 ERROR:  Relation "test" has no column "........pg.dropped.1........"
1016 copy test(b,c) from stdin;
1017 select * from test;
1018  b  | c  
1019 ----+----
1020   2 |  3
1021  21 | 22
1022  31 | 32
1023 (3 rows)
1024
1025 drop table test;