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