1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
|
--
-- MISC
--
--
-- BTREE
--
UPDATE onek
SET unique1 = onek.unique1 + 1;
UPDATE onek
SET unique1 = onek.unique1 - 1;
--
-- BTREE partial
--
-- UPDATE onek2
-- SET unique1 = onek2.unique1 + 1;
--UPDATE onek2
-- SET unique1 = onek2.unique1 - 1;
--
-- BTREE shutting out non-functional updates
--
-- the following two tests seem to take a long time on some
-- systems. This non-func update stuff needs to be examined
-- more closely. - jolly (2/22/96)
--
UPDATE tmp
SET stringu1 = reverse_name(onek.stringu1)
FROM onek
WHERE onek.stringu1 = 'JBAAAA' and
onek.stringu1 = tmp.stringu1;
UPDATE tmp
SET stringu1 = reverse_name(onek2.stringu1)
FROM onek2
WHERE onek2.stringu1 = 'JCAAAA' and
onek2.stringu1 = tmp.stringu1;
DROP TABLE tmp;
--UPDATE person*
-- SET age = age + 1;
--UPDATE person*
-- SET age = age + 3
-- WHERE name = 'linda';
--
-- copy
--
COPY onek TO '@abs_builddir@/results/onek.data';
DELETE FROM onek;
COPY onek FROM '@abs_builddir@/results/onek.data';
SELECT unique1 FROM onek WHERE unique1 < 2 ORDER BY unique1;
unique1
---------
0
1
(2 rows)
DELETE FROM onek2;
COPY onek2 FROM '@abs_builddir@/results/onek.data';
SELECT unique1 FROM onek2 WHERE unique1 < 2 ORDER BY unique1;
unique1
---------
0
1
(2 rows)
COPY BINARY stud_emp TO '@abs_builddir@/results/stud_emp.data';
DELETE FROM stud_emp;
COPY BINARY stud_emp FROM '@abs_builddir@/results/stud_emp.data';
SELECT * FROM stud_emp;
name | age | location | salary | manager | gpa | percent
-------+-----+------------+--------+---------+-----+---------
jeff | 23 | (8,7.7) | 600 | sharon | 3.5 |
cim | 30 | (10.5,4.7) | 400 | | 3.4 |
linda | 19 | (0.9,6.1) | 100 | | 2.9 |
(3 rows)
-- COPY aggtest FROM stdin;
-- 56 7.8
-- 100 99.097
-- 0 0.09561
-- 42 324.78
-- .
-- COPY aggtest TO stdout;
--
-- inheritance stress test
--
SELECT * FROM a_star*;
class | a
-------+----
a | 1
a | 2
a |
b | 3
b | 4
b |
b |
c | 5
c | 6
c |
c |
d | 7
d | 8
d | 9
d | 10
d |
d | 11
d | 12
d | 13
d |
d |
d |
d | 14
d |
d |
d |
d |
e | 15
e | 16
e | 17
e |
e | 18
e |
e |
f | 19
f | 20
f | 21
f | 22
f |
f | 24
f | 25
f | 26
f |
f |
f |
f | 27
f |
f |
f |
f |
(50 rows)
SELECT *
FROM b_star* x
WHERE x.b = text 'bumble' or x.a < 3;
class | a | b
-------+---+--------
b | | bumble
(1 row)
SELECT class, a
FROM c_star* x
WHERE x.c ~ text 'hi';
class | a
-------+----
c | 5
c |
d | 7
d | 8
d | 10
d |
d | 12
d |
d |
d |
e | 15
e | 16
e |
e |
f | 19
f | 20
f | 21
f |
f | 24
f |
f |
f |
(22 rows)
SELECT class, b, c
FROM d_star* x
WHERE x.a < 100;
class | b | c
-------+---------+------------
d | grumble | hi sunita
d | stumble | hi koko
d | rumble |
d | | hi kristin
d | fumble |
d | | hi avi
d | |
d | |
(8 rows)
SELECT class, c FROM e_star* x WHERE x.c NOTNULL;
class | c
-------+-------------
e | hi carol
e | hi bob
e | hi michelle
e | hi elisa
f | hi claire
f | hi mike
f | hi marcel
f | hi keith
f | hi marc
f | hi allison
f | hi jeff
f | hi carl
(12 rows)
SELECT * FROM f_star* x WHERE x.c ISNULL;
class | a | c | e | f
-------+----+---+-----+-------------------------------------------
f | 22 | | -7 | ((111,555),(222,666),(333,777),(444,888))
f | 25 | | -9 |
f | 26 | | | ((11111,33333),(22222,44444))
f | | | -11 | ((1111111,3333333),(2222222,4444444))
f | 27 | | |
f | | | -12 |
f | | | | ((11111111,33333333),(22222222,44444444))
f | | | |
(8 rows)
-- grouping and aggregation on inherited sets have been busted in the past...
SELECT sum(a) FROM a_star*;
sum
-----
355
(1 row)
SELECT class, sum(a) FROM a_star* GROUP BY class ORDER BY class;
class | sum
-------+-----
a | 3
b | 7
c | 11
d | 84
e | 66
f | 184
(6 rows)
ALTER TABLE f_star RENAME COLUMN f TO ff;
ALTER TABLE e_star* RENAME COLUMN e TO ee;
ALTER TABLE d_star* RENAME COLUMN d TO dd;
ALTER TABLE c_star* RENAME COLUMN c TO cc;
ALTER TABLE b_star* RENAME COLUMN b TO bb;
ALTER TABLE a_star* RENAME COLUMN a TO aa;
SELECT class, aa
FROM a_star* x
WHERE aa ISNULL;
class | aa
-------+----
a |
b |
b |
c |
c |
d |
d |
d |
d |
d |
d |
d |
d |
e |
e |
e |
f |
f |
f |
f |
f |
f |
f |
f |
(24 rows)
-- As of Postgres 7.1, ALTER implicitly recurses,
-- so this should be same as ALTER a_star*
ALTER TABLE a_star RENAME COLUMN aa TO foo;
SELECT class, foo
FROM a_star* x
WHERE x.foo >= 2;
class | foo
-------+-----
a | 2
b | 3
b | 4
c | 5
c | 6
d | 7
d | 8
d | 9
d | 10
d | 11
d | 12
d | 13
d | 14
e | 15
e | 16
e | 17
e | 18
f | 19
f | 20
f | 21
f | 22
f | 24
f | 25
f | 26
f | 27
(25 rows)
ALTER TABLE a_star RENAME COLUMN foo TO aa;
SELECT *
from a_star*
WHERE aa < 1000;
class | aa
-------+----
a | 1
a | 2
b | 3
b | 4
c | 5
c | 6
d | 7
d | 8
d | 9
d | 10
d | 11
d | 12
d | 13
d | 14
e | 15
e | 16
e | 17
e | 18
f | 19
f | 20
f | 21
f | 22
f | 24
f | 25
f | 26
f | 27
(26 rows)
ALTER TABLE f_star ADD COLUMN f int4;
UPDATE f_star SET f = 10;
ALTER TABLE e_star* ADD COLUMN e int4;
--UPDATE e_star* SET e = 42;
SELECT * FROM e_star*;
class | aa | cc | ee | e
-------+----+-------------+-----+---
e | 15 | hi carol | -1 |
e | 16 | hi bob | |
e | 17 | | -2 |
e | | hi michelle | -3 |
e | 18 | | |
e | | hi elisa | |
e | | | -4 |
f | 19 | hi claire | -5 |
f | 20 | hi mike | -6 |
f | 21 | hi marcel | |
f | 22 | | -7 |
f | | hi keith | -8 |
f | 24 | hi marc | |
f | 25 | | -9 |
f | 26 | | |
f | | hi allison | -10 |
f | | hi jeff | |
f | | | -11 |
f | 27 | | |
f | | hi carl | |
f | | | -12 |
f | | | |
f | | | |
(23 rows)
ALTER TABLE a_star* ADD COLUMN a text;
NOTICE: merging definition of column "a" for child "d_star"
-- That ALTER TABLE should have added TOAST tables.
SELECT relname, reltoastrelid <> 0 AS has_toast_table
FROM pg_class
WHERE oid::regclass IN ('a_star', 'c_star')
ORDER BY 1;
relname | has_toast_table
---------+-----------------
a_star | t
c_star | t
(2 rows)
--UPDATE b_star*
-- SET a = text 'gazpacho'
-- WHERE aa > 4;
SELECT class, aa, a FROM a_star*;
class | aa | a
-------+----+---
a | 1 |
a | 2 |
a | |
b | 3 |
b | 4 |
b | |
b | |
c | 5 |
c | 6 |
c | |
c | |
d | 7 |
d | 8 |
d | 9 |
d | 10 |
d | |
d | 11 |
d | 12 |
d | 13 |
d | |
d | |
d | |
d | 14 |
d | |
d | |
d | |
d | |
e | 15 |
e | 16 |
e | 17 |
e | |
e | 18 |
e | |
e | |
f | 19 |
f | 20 |
f | 21 |
f | 22 |
f | |
f | 24 |
f | 25 |
f | 26 |
f | |
f | |
f | |
f | 27 |
f | |
f | |
f | |
f | |
(50 rows)
--
-- versions
--
--
-- postquel functions
--
--
-- mike does post_hacking,
-- joe and sally play basketball, and
-- everyone else does nothing.
--
SELECT p.name, name(p.hobbies) FROM ONLY person p;
name | name
-------+-------------
mike | posthacking
joe | basketball
sally | basketball
(3 rows)
--
-- as above, but jeff also does post_hacking.
--
SELECT p.name, name(p.hobbies) FROM person* p;
name | name
-------+-------------
mike | posthacking
joe | basketball
sally | basketball
jeff | posthacking
(4 rows)
--
-- the next two queries demonstrate how functions generate bogus duplicates.
-- this is a "feature" ..
--
SELECT DISTINCT hobbies_r.name, name(hobbies_r.equipment) FROM hobbies_r
ORDER BY 1,2;
name | name
-------------+---------------
basketball | hightops
posthacking | advil
posthacking | peet's coffee
skywalking | guts
(4 rows)
SELECT hobbies_r.name, (hobbies_r.equipment).name FROM hobbies_r;
name | name
-------------+---------------
posthacking | advil
posthacking | peet's coffee
posthacking | advil
posthacking | peet's coffee
basketball | hightops
basketball | hightops
skywalking | guts
(7 rows)
--
-- mike needs advil and peet's coffee,
-- joe and sally need hightops, and
-- everyone else is fine.
--
SELECT p.name, name(p.hobbies), name(equipment(p.hobbies)) FROM ONLY person p;
name | name | name
-------+-------------+---------------
mike | posthacking | advil
mike | posthacking | peet's coffee
joe | basketball | hightops
sally | basketball | hightops
(4 rows)
--
-- as above, but jeff needs advil and peet's coffee as well.
--
SELECT p.name, name(p.hobbies), name(equipment(p.hobbies)) FROM person* p;
name | name | name
-------+-------------+---------------
mike | posthacking | advil
mike | posthacking | peet's coffee
joe | basketball | hightops
sally | basketball | hightops
jeff | posthacking | advil
jeff | posthacking | peet's coffee
(6 rows)
--
-- just like the last two, but make sure that the target list fixup and
-- unflattening is being done correctly.
--
SELECT name(equipment(p.hobbies)), p.name, name(p.hobbies) FROM ONLY person p;
name | name | name
---------------+-------+-------------
advil | mike | posthacking
peet's coffee | mike | posthacking
hightops | joe | basketball
hightops | sally | basketball
(4 rows)
SELECT (p.hobbies).equipment.name, p.name, name(p.hobbies) FROM person* p;
name | name | name
---------------+-------+-------------
advil | mike | posthacking
peet's coffee | mike | posthacking
hightops | joe | basketball
hightops | sally | basketball
advil | jeff | posthacking
peet's coffee | jeff | posthacking
(6 rows)
SELECT (p.hobbies).equipment.name, name(p.hobbies), p.name FROM ONLY person p;
name | name | name
---------------+-------------+-------
advil | posthacking | mike
peet's coffee | posthacking | mike
hightops | basketball | joe
hightops | basketball | sally
(4 rows)
SELECT name(equipment(p.hobbies)), name(p.hobbies), p.name FROM person* p;
name | name | name
---------------+-------------+-------
advil | posthacking | mike
peet's coffee | posthacking | mike
hightops | basketball | joe
hightops | basketball | sally
advil | posthacking | jeff
peet's coffee | posthacking | jeff
(6 rows)
SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer')));
name
------
guts
(1 row)
SELECT name(equipment(hobby_construct_named(text 'skywalking', text 'mer')));
name
------
guts
(1 row)
SELECT name(equipment_named(hobby_construct_named(text 'skywalking', text 'mer')));
name
------
guts
(1 row)
SELECT name(equipment_named_ambiguous_1a(hobby_construct_named(text 'skywalking', text 'mer')));
name
------
guts
(1 row)
SELECT name(equipment_named_ambiguous_1b(hobby_construct_named(text 'skywalking', text 'mer')));
name
------
guts
(1 row)
SELECT name(equipment_named_ambiguous_1c(hobby_construct_named(text 'skywalking', text 'mer')));
name
------
guts
(1 row)
SELECT name(equipment_named_ambiguous_2a(text 'skywalking'));
name
------
guts
(1 row)
SELECT name(equipment_named_ambiguous_2b(text 'skywalking'));
name
---------------
advil
peet's coffee
hightops
guts
(4 rows)
SELECT hobbies_by_name('basketball');
hobbies_by_name
-----------------
joe
(1 row)
SELECT name, overpaid(emp.*) FROM emp;
name | overpaid
--------+----------
sharon | t
sam | t
bill | t
jeff | f
cim | f
linda | f
(6 rows)
--
-- Try a few cases with SQL-spec row constructor expressions
--
SELECT * FROM equipment(ROW('skywalking', 'mer'));
name | hobby
------+------------
guts | skywalking
(1 row)
SELECT name(equipment(ROW('skywalking', 'mer')));
name
------
guts
(1 row)
SELECT *, name(equipment(h.*)) FROM hobbies_r h;
name | person | name
-------------+--------+---------------
posthacking | mike | advil
posthacking | mike | peet's coffee
posthacking | jeff | advil
posthacking | jeff | peet's coffee
basketball | joe | hightops
basketball | sally | hightops
skywalking | | guts
(7 rows)
SELECT *, (equipment(CAST((h.*) AS hobbies_r))).name FROM hobbies_r h;
name | person | name
-------------+--------+---------------
posthacking | mike | advil
posthacking | mike | peet's coffee
posthacking | jeff | advil
posthacking | jeff | peet's coffee
basketball | joe | hightops
basketball | sally | hightops
skywalking | | guts
(7 rows)
--
-- functional joins
--
--
-- instance rules
--
--
-- rewrite rules
--
|