portals.out 70.9 KB
Newer Older
V
Venkatesh Raghavan 已提交
1
set optimizer_print_missing_stats = off;
2
--
3
-- Cursor regression tests
4 5
--
BEGIN;
6
DECLARE foo1 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
7
DECLARE foo2 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
8
DECLARE foo3 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
9
DECLARE foo4 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
10
DECLARE foo5 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
11
DECLARE foo6 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
12
DECLARE foo7 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
13
DECLARE foo8 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
14
DECLARE foo9 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
15
DECLARE foo10 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
16
DECLARE foo11 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
17
DECLARE foo12 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
18
DECLARE foo13 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
19
DECLARE foo14 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
20
DECLARE foo15 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
21
DECLARE foo16 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
22
DECLARE foo17 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
23
DECLARE foo18 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
24
DECLARE foo19 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
25
DECLARE foo20 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
26
DECLARE foo21 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
27
DECLARE foo22 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
28
DECLARE foo23 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
29 30 31 32
FETCH 1 in foo1;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
33 34
(1 row)

35 36 37
FETCH 2 in foo2;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
38 39
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
40 41
(2 rows)

42 43 44 45 46 47
FETCH 3 in foo3;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
48 49
(3 rows)

50 51 52
FETCH 4 in foo4;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
53 54 55 56
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
       3 |    5679 |   1 |    3 |   3 |      3 |       3 |        3 |           3 |         3 |        3 |   6 |    7 | DAAAAA   | LKIAAA   | VVVVxx
57 58
(4 rows)

59 60 61 62 63 64
FETCH 5 in foo5;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    9850 |       3 |   0 |    2 |   0 |     10 |      50 |      850 |        1850 |      4850 |     9850 | 100 |  101 | WOAAAA   | DAAAAA   | VVVVxx
65
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
66
    7164 |       4 |   0 |    0 |   4 |      4 |      64 |      164 |        1164 |      2164 |     7164 | 128 |  129 | OPAAAA   | EAAAAA   | AAAAxx
67 68
(5 rows)

69 70 71
FETCH 6 in foo6;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
72 73 74 75 76 77
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
       3 |    5679 |   1 |    3 |   3 |      3 |       3 |        3 |           3 |         3 |        3 |   6 |    7 | DAAAAA   | LKIAAA   | VVVVxx
       4 |    1621 |   0 |    0 |   4 |      4 |       4 |        4 |           4 |         4 |        4 |   8 |    9 | EAAAAA   | JKCAAA   | HHHHxx
       5 |    5557 |   1 |    1 |   5 |      5 |       5 |        5 |           5 |         5 |        5 |  10 |   11 | FAAAAA   | TFIAAA   | HHHHxx
78 79
(6 rows)

80 81 82 83 84 85 86 87 88 89
FETCH 7 in foo7;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
    9850 |       3 |   0 |    2 |   0 |     10 |      50 |      850 |        1850 |      4850 |     9850 | 100 |  101 | WOAAAA   | DAAAAA   | VVVVxx
    7164 |       4 |   0 |    0 |   4 |      4 |      64 |      164 |        1164 |      2164 |     7164 | 128 |  129 | OPAAAA   | EAAAAA   | AAAAxx
    8009 |       5 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |      3009 |     8009 |  18 |   19 | BWAAAA   | FAAAAA   | HHHHxx
    5057 |       6 |   1 |    1 |   7 |     17 |      57 |       57 |        1057 |        57 |     5057 | 114 |  115 | NMAAAA   | GAAAAA   | OOOOxx
90 91
(7 rows)

92 93 94
FETCH 8 in foo8;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
95 96 97 98 99 100 101 102
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
       3 |    5679 |   1 |    3 |   3 |      3 |       3 |        3 |           3 |         3 |        3 |   6 |    7 | DAAAAA   | LKIAAA   | VVVVxx
       4 |    1621 |   0 |    0 |   4 |      4 |       4 |        4 |           4 |         4 |        4 |   8 |    9 | EAAAAA   | JKCAAA   | HHHHxx
       5 |    5557 |   1 |    1 |   5 |      5 |       5 |        5 |           5 |         5 |        5 |  10 |   11 | FAAAAA   | TFIAAA   | HHHHxx
       6 |    2855 |   0 |    2 |   6 |      6 |       6 |        6 |           6 |         6 |        6 |  12 |   13 | GAAAAA   | VFEAAA   | VVVVxx
       7 |    8518 |   1 |    3 |   7 |      7 |       7 |        7 |           7 |         7 |        7 |  14 |   15 | HAAAAA   | QPMAAA   | OOOOxx
103 104
(8 rows)

105 106 107 108 109 110 111 112 113 114 115 116
FETCH 9 in foo9;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
    9850 |       3 |   0 |    2 |   0 |     10 |      50 |      850 |        1850 |      4850 |     9850 | 100 |  101 | WOAAAA   | DAAAAA   | VVVVxx
    7164 |       4 |   0 |    0 |   4 |      4 |      64 |      164 |        1164 |      2164 |     7164 | 128 |  129 | OPAAAA   | EAAAAA   | AAAAxx
    8009 |       5 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |      3009 |     8009 |  18 |   19 | BWAAAA   | FAAAAA   | HHHHxx
    5057 |       6 |   1 |    1 |   7 |     17 |      57 |       57 |        1057 |        57 |     5057 | 114 |  115 | NMAAAA   | GAAAAA   | OOOOxx
    6701 |       7 |   1 |    1 |   1 |      1 |       1 |      701 |         701 |      1701 |     6701 |   2 |    3 | TXAAAA   | HAAAAA   | VVVVxx
    4321 |       8 |   1 |    1 |   1 |      1 |      21 |      321 |         321 |      4321 |     4321 |  42 |   43 | FKAAAA   | IAAAAA   | AAAAxx
117 118
(9 rows)

119 120 121
FETCH 10 in foo10;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
122 123 124 125 126 127 128 129 130 131
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
       3 |    5679 |   1 |    3 |   3 |      3 |       3 |        3 |           3 |         3 |        3 |   6 |    7 | DAAAAA   | LKIAAA   | VVVVxx
       4 |    1621 |   0 |    0 |   4 |      4 |       4 |        4 |           4 |         4 |        4 |   8 |    9 | EAAAAA   | JKCAAA   | HHHHxx
       5 |    5557 |   1 |    1 |   5 |      5 |       5 |        5 |           5 |         5 |        5 |  10 |   11 | FAAAAA   | TFIAAA   | HHHHxx
       6 |    2855 |   0 |    2 |   6 |      6 |       6 |        6 |           6 |         6 |        6 |  12 |   13 | GAAAAA   | VFEAAA   | VVVVxx
       7 |    8518 |   1 |    3 |   7 |      7 |       7 |        7 |           7 |         7 |        7 |  14 |   15 | HAAAAA   | QPMAAA   | OOOOxx
       8 |    5435 |   0 |    0 |   8 |      8 |       8 |        8 |           8 |         8 |        8 |  16 |   17 | IAAAAA   | BBIAAA   | VVVVxx
       9 |    4463 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |         9 |        9 |  18 |   19 | JAAAAA   | RPGAAA   | VVVVxx
132 133
(10 rows)

134 135 136 137 138 139 140 141 142 143 144 145 146 147
FETCH 11 in foo11;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
    9850 |       3 |   0 |    2 |   0 |     10 |      50 |      850 |        1850 |      4850 |     9850 | 100 |  101 | WOAAAA   | DAAAAA   | VVVVxx
    7164 |       4 |   0 |    0 |   4 |      4 |      64 |      164 |        1164 |      2164 |     7164 | 128 |  129 | OPAAAA   | EAAAAA   | AAAAxx
    8009 |       5 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |      3009 |     8009 |  18 |   19 | BWAAAA   | FAAAAA   | HHHHxx
    5057 |       6 |   1 |    1 |   7 |     17 |      57 |       57 |        1057 |        57 |     5057 | 114 |  115 | NMAAAA   | GAAAAA   | OOOOxx
    6701 |       7 |   1 |    1 |   1 |      1 |       1 |      701 |         701 |      1701 |     6701 |   2 |    3 | TXAAAA   | HAAAAA   | VVVVxx
    4321 |       8 |   1 |    1 |   1 |      1 |      21 |      321 |         321 |      4321 |     4321 |  42 |   43 | FKAAAA   | IAAAAA   | AAAAxx
    3043 |       9 |   1 |    3 |   3 |      3 |      43 |       43 |        1043 |      3043 |     3043 |  86 |   87 | BNAAAA   | JAAAAA   | HHHHxx
    1314 |      10 |   0 |    2 |   4 |     14 |      14 |      314 |        1314 |      1314 |     1314 |  28 |   29 | OYAAAA   | KAAAAA   | OOOOxx
148 149
(11 rows)

150 151 152
FETCH 12 in foo12;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
153 154 155 156 157 158 159 160 161 162 163 164
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
       3 |    5679 |   1 |    3 |   3 |      3 |       3 |        3 |           3 |         3 |        3 |   6 |    7 | DAAAAA   | LKIAAA   | VVVVxx
       4 |    1621 |   0 |    0 |   4 |      4 |       4 |        4 |           4 |         4 |        4 |   8 |    9 | EAAAAA   | JKCAAA   | HHHHxx
       5 |    5557 |   1 |    1 |   5 |      5 |       5 |        5 |           5 |         5 |        5 |  10 |   11 | FAAAAA   | TFIAAA   | HHHHxx
       6 |    2855 |   0 |    2 |   6 |      6 |       6 |        6 |           6 |         6 |        6 |  12 |   13 | GAAAAA   | VFEAAA   | VVVVxx
       7 |    8518 |   1 |    3 |   7 |      7 |       7 |        7 |           7 |         7 |        7 |  14 |   15 | HAAAAA   | QPMAAA   | OOOOxx
       8 |    5435 |   0 |    0 |   8 |      8 |       8 |        8 |           8 |         8 |        8 |  16 |   17 | IAAAAA   | BBIAAA   | VVVVxx
       9 |    4463 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |         9 |        9 |  18 |   19 | JAAAAA   | RPGAAA   | VVVVxx
      10 |    8788 |   0 |    2 |   0 |     10 |      10 |       10 |          10 |        10 |       10 |  20 |   21 | KAAAAA   | AANAAA   | AAAAxx
      11 |    8396 |   1 |    3 |   1 |     11 |      11 |       11 |          11 |        11 |       11 |  22 |   23 | LAAAAA   | YKMAAA   | AAAAxx
165 166
(12 rows)

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
FETCH 13 in foo13;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
    9850 |       3 |   0 |    2 |   0 |     10 |      50 |      850 |        1850 |      4850 |     9850 | 100 |  101 | WOAAAA   | DAAAAA   | VVVVxx
    7164 |       4 |   0 |    0 |   4 |      4 |      64 |      164 |        1164 |      2164 |     7164 | 128 |  129 | OPAAAA   | EAAAAA   | AAAAxx
    8009 |       5 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |      3009 |     8009 |  18 |   19 | BWAAAA   | FAAAAA   | HHHHxx
    5057 |       6 |   1 |    1 |   7 |     17 |      57 |       57 |        1057 |        57 |     5057 | 114 |  115 | NMAAAA   | GAAAAA   | OOOOxx
    6701 |       7 |   1 |    1 |   1 |      1 |       1 |      701 |         701 |      1701 |     6701 |   2 |    3 | TXAAAA   | HAAAAA   | VVVVxx
    4321 |       8 |   1 |    1 |   1 |      1 |      21 |      321 |         321 |      4321 |     4321 |  42 |   43 | FKAAAA   | IAAAAA   | AAAAxx
    3043 |       9 |   1 |    3 |   3 |      3 |      43 |       43 |        1043 |      3043 |     3043 |  86 |   87 | BNAAAA   | JAAAAA   | HHHHxx
    1314 |      10 |   0 |    2 |   4 |     14 |      14 |      314 |        1314 |      1314 |     1314 |  28 |   29 | OYAAAA   | KAAAAA   | OOOOxx
    1504 |      11 |   0 |    0 |   4 |      4 |       4 |      504 |        1504 |      1504 |     1504 |   8 |    9 | WFAAAA   | LAAAAA   | VVVVxx
    5222 |      12 |   0 |    2 |   2 |      2 |      22 |      222 |        1222 |       222 |     5222 |  44 |   45 | WSAAAA   | MAAAAA   | AAAAxx
183 184
(13 rows)

185 186 187
FETCH 14 in foo14;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
188 189 190 191 192 193 194 195 196 197 198 199 200 201
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
       3 |    5679 |   1 |    3 |   3 |      3 |       3 |        3 |           3 |         3 |        3 |   6 |    7 | DAAAAA   | LKIAAA   | VVVVxx
       4 |    1621 |   0 |    0 |   4 |      4 |       4 |        4 |           4 |         4 |        4 |   8 |    9 | EAAAAA   | JKCAAA   | HHHHxx
       5 |    5557 |   1 |    1 |   5 |      5 |       5 |        5 |           5 |         5 |        5 |  10 |   11 | FAAAAA   | TFIAAA   | HHHHxx
       6 |    2855 |   0 |    2 |   6 |      6 |       6 |        6 |           6 |         6 |        6 |  12 |   13 | GAAAAA   | VFEAAA   | VVVVxx
       7 |    8518 |   1 |    3 |   7 |      7 |       7 |        7 |           7 |         7 |        7 |  14 |   15 | HAAAAA   | QPMAAA   | OOOOxx
       8 |    5435 |   0 |    0 |   8 |      8 |       8 |        8 |           8 |         8 |        8 |  16 |   17 | IAAAAA   | BBIAAA   | VVVVxx
       9 |    4463 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |         9 |        9 |  18 |   19 | JAAAAA   | RPGAAA   | VVVVxx
      10 |    8788 |   0 |    2 |   0 |     10 |      10 |       10 |          10 |        10 |       10 |  20 |   21 | KAAAAA   | AANAAA   | AAAAxx
      11 |    8396 |   1 |    3 |   1 |     11 |      11 |       11 |          11 |        11 |       11 |  22 |   23 | LAAAAA   | YKMAAA   | AAAAxx
      12 |    6605 |   0 |    0 |   2 |     12 |      12 |       12 |          12 |        12 |       12 |  24 |   25 | MAAAAA   | BUJAAA   | HHHHxx
      13 |    5696 |   1 |    1 |   3 |     13 |      13 |       13 |          13 |        13 |       13 |  26 |   27 | NAAAAA   | CLIAAA   | AAAAxx
202 203
(14 rows)

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
FETCH 15 in foo15;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
    9850 |       3 |   0 |    2 |   0 |     10 |      50 |      850 |        1850 |      4850 |     9850 | 100 |  101 | WOAAAA   | DAAAAA   | VVVVxx
    7164 |       4 |   0 |    0 |   4 |      4 |      64 |      164 |        1164 |      2164 |     7164 | 128 |  129 | OPAAAA   | EAAAAA   | AAAAxx
    8009 |       5 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |      3009 |     8009 |  18 |   19 | BWAAAA   | FAAAAA   | HHHHxx
    5057 |       6 |   1 |    1 |   7 |     17 |      57 |       57 |        1057 |        57 |     5057 | 114 |  115 | NMAAAA   | GAAAAA   | OOOOxx
    6701 |       7 |   1 |    1 |   1 |      1 |       1 |      701 |         701 |      1701 |     6701 |   2 |    3 | TXAAAA   | HAAAAA   | VVVVxx
    4321 |       8 |   1 |    1 |   1 |      1 |      21 |      321 |         321 |      4321 |     4321 |  42 |   43 | FKAAAA   | IAAAAA   | AAAAxx
    3043 |       9 |   1 |    3 |   3 |      3 |      43 |       43 |        1043 |      3043 |     3043 |  86 |   87 | BNAAAA   | JAAAAA   | HHHHxx
    1314 |      10 |   0 |    2 |   4 |     14 |      14 |      314 |        1314 |      1314 |     1314 |  28 |   29 | OYAAAA   | KAAAAA   | OOOOxx
    1504 |      11 |   0 |    0 |   4 |      4 |       4 |      504 |        1504 |      1504 |     1504 |   8 |    9 | WFAAAA   | LAAAAA   | VVVVxx
    5222 |      12 |   0 |    2 |   2 |      2 |      22 |      222 |        1222 |       222 |     5222 |  44 |   45 | WSAAAA   | MAAAAA   | AAAAxx
    6243 |      13 |   1 |    3 |   3 |      3 |      43 |      243 |         243 |      1243 |     6243 |  86 |   87 | DGAAAA   | NAAAAA   | HHHHxx
    5471 |      14 |   1 |    3 |   1 |     11 |      71 |      471 |        1471 |       471 |     5471 | 142 |  143 | LCAAAA   | OAAAAA   | OOOOxx
222 223
(15 rows)

224 225 226
FETCH 16 in foo16;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
       3 |    5679 |   1 |    3 |   3 |      3 |       3 |        3 |           3 |         3 |        3 |   6 |    7 | DAAAAA   | LKIAAA   | VVVVxx
       4 |    1621 |   0 |    0 |   4 |      4 |       4 |        4 |           4 |         4 |        4 |   8 |    9 | EAAAAA   | JKCAAA   | HHHHxx
       5 |    5557 |   1 |    1 |   5 |      5 |       5 |        5 |           5 |         5 |        5 |  10 |   11 | FAAAAA   | TFIAAA   | HHHHxx
       6 |    2855 |   0 |    2 |   6 |      6 |       6 |        6 |           6 |         6 |        6 |  12 |   13 | GAAAAA   | VFEAAA   | VVVVxx
       7 |    8518 |   1 |    3 |   7 |      7 |       7 |        7 |           7 |         7 |        7 |  14 |   15 | HAAAAA   | QPMAAA   | OOOOxx
       8 |    5435 |   0 |    0 |   8 |      8 |       8 |        8 |           8 |         8 |        8 |  16 |   17 | IAAAAA   | BBIAAA   | VVVVxx
       9 |    4463 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |         9 |        9 |  18 |   19 | JAAAAA   | RPGAAA   | VVVVxx
      10 |    8788 |   0 |    2 |   0 |     10 |      10 |       10 |          10 |        10 |       10 |  20 |   21 | KAAAAA   | AANAAA   | AAAAxx
      11 |    8396 |   1 |    3 |   1 |     11 |      11 |       11 |          11 |        11 |       11 |  22 |   23 | LAAAAA   | YKMAAA   | AAAAxx
      12 |    6605 |   0 |    0 |   2 |     12 |      12 |       12 |          12 |        12 |       12 |  24 |   25 | MAAAAA   | BUJAAA   | HHHHxx
      13 |    5696 |   1 |    1 |   3 |     13 |      13 |       13 |          13 |        13 |       13 |  26 |   27 | NAAAAA   | CLIAAA   | AAAAxx
      14 |    4341 |   0 |    2 |   4 |     14 |      14 |       14 |          14 |        14 |       14 |  28 |   29 | OAAAAA   | ZKGAAA   | HHHHxx
      15 |    1358 |   1 |    3 |   5 |     15 |      15 |       15 |          15 |        15 |       15 |  30 |   31 | PAAAAA   | GACAAA   | OOOOxx
243 244
(16 rows)

245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
FETCH 17 in foo17;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
    9850 |       3 |   0 |    2 |   0 |     10 |      50 |      850 |        1850 |      4850 |     9850 | 100 |  101 | WOAAAA   | DAAAAA   | VVVVxx
    7164 |       4 |   0 |    0 |   4 |      4 |      64 |      164 |        1164 |      2164 |     7164 | 128 |  129 | OPAAAA   | EAAAAA   | AAAAxx
    8009 |       5 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |      3009 |     8009 |  18 |   19 | BWAAAA   | FAAAAA   | HHHHxx
    5057 |       6 |   1 |    1 |   7 |     17 |      57 |       57 |        1057 |        57 |     5057 | 114 |  115 | NMAAAA   | GAAAAA   | OOOOxx
    6701 |       7 |   1 |    1 |   1 |      1 |       1 |      701 |         701 |      1701 |     6701 |   2 |    3 | TXAAAA   | HAAAAA   | VVVVxx
    4321 |       8 |   1 |    1 |   1 |      1 |      21 |      321 |         321 |      4321 |     4321 |  42 |   43 | FKAAAA   | IAAAAA   | AAAAxx
    3043 |       9 |   1 |    3 |   3 |      3 |      43 |       43 |        1043 |      3043 |     3043 |  86 |   87 | BNAAAA   | JAAAAA   | HHHHxx
    1314 |      10 |   0 |    2 |   4 |     14 |      14 |      314 |        1314 |      1314 |     1314 |  28 |   29 | OYAAAA   | KAAAAA   | OOOOxx
    1504 |      11 |   0 |    0 |   4 |      4 |       4 |      504 |        1504 |      1504 |     1504 |   8 |    9 | WFAAAA   | LAAAAA   | VVVVxx
    5222 |      12 |   0 |    2 |   2 |      2 |      22 |      222 |        1222 |       222 |     5222 |  44 |   45 | WSAAAA   | MAAAAA   | AAAAxx
    6243 |      13 |   1 |    3 |   3 |      3 |      43 |      243 |         243 |      1243 |     6243 |  86 |   87 | DGAAAA   | NAAAAA   | HHHHxx
    5471 |      14 |   1 |    3 |   1 |     11 |      71 |      471 |        1471 |       471 |     5471 | 142 |  143 | LCAAAA   | OAAAAA   | OOOOxx
    5006 |      15 |   0 |    2 |   6 |      6 |       6 |        6 |        1006 |         6 |     5006 |  12 |   13 | OKAAAA   | PAAAAA   | VVVVxx
    5387 |      16 |   1 |    3 |   7 |      7 |      87 |      387 |        1387 |       387 |     5387 | 174 |  175 | FZAAAA   | QAAAAA   | AAAAxx
265 266
(17 rows)

267 268 269
FETCH 18 in foo18;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
       3 |    5679 |   1 |    3 |   3 |      3 |       3 |        3 |           3 |         3 |        3 |   6 |    7 | DAAAAA   | LKIAAA   | VVVVxx
       4 |    1621 |   0 |    0 |   4 |      4 |       4 |        4 |           4 |         4 |        4 |   8 |    9 | EAAAAA   | JKCAAA   | HHHHxx
       5 |    5557 |   1 |    1 |   5 |      5 |       5 |        5 |           5 |         5 |        5 |  10 |   11 | FAAAAA   | TFIAAA   | HHHHxx
       6 |    2855 |   0 |    2 |   6 |      6 |       6 |        6 |           6 |         6 |        6 |  12 |   13 | GAAAAA   | VFEAAA   | VVVVxx
       7 |    8518 |   1 |    3 |   7 |      7 |       7 |        7 |           7 |         7 |        7 |  14 |   15 | HAAAAA   | QPMAAA   | OOOOxx
       8 |    5435 |   0 |    0 |   8 |      8 |       8 |        8 |           8 |         8 |        8 |  16 |   17 | IAAAAA   | BBIAAA   | VVVVxx
       9 |    4463 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |         9 |        9 |  18 |   19 | JAAAAA   | RPGAAA   | VVVVxx
      10 |    8788 |   0 |    2 |   0 |     10 |      10 |       10 |          10 |        10 |       10 |  20 |   21 | KAAAAA   | AANAAA   | AAAAxx
      11 |    8396 |   1 |    3 |   1 |     11 |      11 |       11 |          11 |        11 |       11 |  22 |   23 | LAAAAA   | YKMAAA   | AAAAxx
      12 |    6605 |   0 |    0 |   2 |     12 |      12 |       12 |          12 |        12 |       12 |  24 |   25 | MAAAAA   | BUJAAA   | HHHHxx
      13 |    5696 |   1 |    1 |   3 |     13 |      13 |       13 |          13 |        13 |       13 |  26 |   27 | NAAAAA   | CLIAAA   | AAAAxx
      14 |    4341 |   0 |    2 |   4 |     14 |      14 |       14 |          14 |        14 |       14 |  28 |   29 | OAAAAA   | ZKGAAA   | HHHHxx
      15 |    1358 |   1 |    3 |   5 |     15 |      15 |       15 |          15 |        15 |       15 |  30 |   31 | PAAAAA   | GACAAA   | OOOOxx
      16 |    9675 |   0 |    0 |   6 |     16 |      16 |       16 |          16 |        16 |       16 |  32 |   33 | QAAAAA   | DIOAAA   | VVVVxx
      17 |    8274 |   1 |    1 |   7 |     17 |      17 |       17 |          17 |        17 |       17 |  34 |   35 | RAAAAA   | GGMAAA   | OOOOxx
288 289
(18 rows)

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
FETCH 19 in foo19;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
    9850 |       3 |   0 |    2 |   0 |     10 |      50 |      850 |        1850 |      4850 |     9850 | 100 |  101 | WOAAAA   | DAAAAA   | VVVVxx
    7164 |       4 |   0 |    0 |   4 |      4 |      64 |      164 |        1164 |      2164 |     7164 | 128 |  129 | OPAAAA   | EAAAAA   | AAAAxx
    8009 |       5 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |      3009 |     8009 |  18 |   19 | BWAAAA   | FAAAAA   | HHHHxx
    5057 |       6 |   1 |    1 |   7 |     17 |      57 |       57 |        1057 |        57 |     5057 | 114 |  115 | NMAAAA   | GAAAAA   | OOOOxx
    6701 |       7 |   1 |    1 |   1 |      1 |       1 |      701 |         701 |      1701 |     6701 |   2 |    3 | TXAAAA   | HAAAAA   | VVVVxx
    4321 |       8 |   1 |    1 |   1 |      1 |      21 |      321 |         321 |      4321 |     4321 |  42 |   43 | FKAAAA   | IAAAAA   | AAAAxx
    3043 |       9 |   1 |    3 |   3 |      3 |      43 |       43 |        1043 |      3043 |     3043 |  86 |   87 | BNAAAA   | JAAAAA   | HHHHxx
    1314 |      10 |   0 |    2 |   4 |     14 |      14 |      314 |        1314 |      1314 |     1314 |  28 |   29 | OYAAAA   | KAAAAA   | OOOOxx
    1504 |      11 |   0 |    0 |   4 |      4 |       4 |      504 |        1504 |      1504 |     1504 |   8 |    9 | WFAAAA   | LAAAAA   | VVVVxx
    5222 |      12 |   0 |    2 |   2 |      2 |      22 |      222 |        1222 |       222 |     5222 |  44 |   45 | WSAAAA   | MAAAAA   | AAAAxx
    6243 |      13 |   1 |    3 |   3 |      3 |      43 |      243 |         243 |      1243 |     6243 |  86 |   87 | DGAAAA   | NAAAAA   | HHHHxx
    5471 |      14 |   1 |    3 |   1 |     11 |      71 |      471 |        1471 |       471 |     5471 | 142 |  143 | LCAAAA   | OAAAAA   | OOOOxx
    5006 |      15 |   0 |    2 |   6 |      6 |       6 |        6 |        1006 |         6 |     5006 |  12 |   13 | OKAAAA   | PAAAAA   | VVVVxx
    5387 |      16 |   1 |    3 |   7 |      7 |      87 |      387 |        1387 |       387 |     5387 | 174 |  175 | FZAAAA   | QAAAAA   | AAAAxx
    5785 |      17 |   1 |    1 |   5 |      5 |      85 |      785 |        1785 |       785 |     5785 | 170 |  171 | NOAAAA   | RAAAAA   | HHHHxx
    6621 |      18 |   1 |    1 |   1 |      1 |      21 |      621 |         621 |      1621 |     6621 |  42 |   43 | RUAAAA   | SAAAAA   | OOOOxx
312 313
(19 rows)

314 315 316
FETCH 20 in foo20;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
       3 |    5679 |   1 |    3 |   3 |      3 |       3 |        3 |           3 |         3 |        3 |   6 |    7 | DAAAAA   | LKIAAA   | VVVVxx
       4 |    1621 |   0 |    0 |   4 |      4 |       4 |        4 |           4 |         4 |        4 |   8 |    9 | EAAAAA   | JKCAAA   | HHHHxx
       5 |    5557 |   1 |    1 |   5 |      5 |       5 |        5 |           5 |         5 |        5 |  10 |   11 | FAAAAA   | TFIAAA   | HHHHxx
       6 |    2855 |   0 |    2 |   6 |      6 |       6 |        6 |           6 |         6 |        6 |  12 |   13 | GAAAAA   | VFEAAA   | VVVVxx
       7 |    8518 |   1 |    3 |   7 |      7 |       7 |        7 |           7 |         7 |        7 |  14 |   15 | HAAAAA   | QPMAAA   | OOOOxx
       8 |    5435 |   0 |    0 |   8 |      8 |       8 |        8 |           8 |         8 |        8 |  16 |   17 | IAAAAA   | BBIAAA   | VVVVxx
       9 |    4463 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |         9 |        9 |  18 |   19 | JAAAAA   | RPGAAA   | VVVVxx
      10 |    8788 |   0 |    2 |   0 |     10 |      10 |       10 |          10 |        10 |       10 |  20 |   21 | KAAAAA   | AANAAA   | AAAAxx
      11 |    8396 |   1 |    3 |   1 |     11 |      11 |       11 |          11 |        11 |       11 |  22 |   23 | LAAAAA   | YKMAAA   | AAAAxx
      12 |    6605 |   0 |    0 |   2 |     12 |      12 |       12 |          12 |        12 |       12 |  24 |   25 | MAAAAA   | BUJAAA   | HHHHxx
      13 |    5696 |   1 |    1 |   3 |     13 |      13 |       13 |          13 |        13 |       13 |  26 |   27 | NAAAAA   | CLIAAA   | AAAAxx
      14 |    4341 |   0 |    2 |   4 |     14 |      14 |       14 |          14 |        14 |       14 |  28 |   29 | OAAAAA   | ZKGAAA   | HHHHxx
      15 |    1358 |   1 |    3 |   5 |     15 |      15 |       15 |          15 |        15 |       15 |  30 |   31 | PAAAAA   | GACAAA   | OOOOxx
      16 |    9675 |   0 |    0 |   6 |     16 |      16 |       16 |          16 |        16 |       16 |  32 |   33 | QAAAAA   | DIOAAA   | VVVVxx
      17 |    8274 |   1 |    1 |   7 |     17 |      17 |       17 |          17 |        17 |       17 |  34 |   35 | RAAAAA   | GGMAAA   | OOOOxx
      18 |     376 |   0 |    2 |   8 |     18 |      18 |       18 |          18 |        18 |       18 |  36 |   37 | SAAAAA   | MOAAAA   | AAAAxx
      19 |    7303 |   1 |    3 |   9 |     19 |      19 |       19 |          19 |        19 |       19 |  38 |   39 | TAAAAA   | XUKAAA   | VVVVxx
337 338
(20 rows)

339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
FETCH 21 in foo21;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
    9850 |       3 |   0 |    2 |   0 |     10 |      50 |      850 |        1850 |      4850 |     9850 | 100 |  101 | WOAAAA   | DAAAAA   | VVVVxx
    7164 |       4 |   0 |    0 |   4 |      4 |      64 |      164 |        1164 |      2164 |     7164 | 128 |  129 | OPAAAA   | EAAAAA   | AAAAxx
    8009 |       5 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |      3009 |     8009 |  18 |   19 | BWAAAA   | FAAAAA   | HHHHxx
    5057 |       6 |   1 |    1 |   7 |     17 |      57 |       57 |        1057 |        57 |     5057 | 114 |  115 | NMAAAA   | GAAAAA   | OOOOxx
    6701 |       7 |   1 |    1 |   1 |      1 |       1 |      701 |         701 |      1701 |     6701 |   2 |    3 | TXAAAA   | HAAAAA   | VVVVxx
    4321 |       8 |   1 |    1 |   1 |      1 |      21 |      321 |         321 |      4321 |     4321 |  42 |   43 | FKAAAA   | IAAAAA   | AAAAxx
    3043 |       9 |   1 |    3 |   3 |      3 |      43 |       43 |        1043 |      3043 |     3043 |  86 |   87 | BNAAAA   | JAAAAA   | HHHHxx
    1314 |      10 |   0 |    2 |   4 |     14 |      14 |      314 |        1314 |      1314 |     1314 |  28 |   29 | OYAAAA   | KAAAAA   | OOOOxx
    1504 |      11 |   0 |    0 |   4 |      4 |       4 |      504 |        1504 |      1504 |     1504 |   8 |    9 | WFAAAA   | LAAAAA   | VVVVxx
    5222 |      12 |   0 |    2 |   2 |      2 |      22 |      222 |        1222 |       222 |     5222 |  44 |   45 | WSAAAA   | MAAAAA   | AAAAxx
    6243 |      13 |   1 |    3 |   3 |      3 |      43 |      243 |         243 |      1243 |     6243 |  86 |   87 | DGAAAA   | NAAAAA   | HHHHxx
    5471 |      14 |   1 |    3 |   1 |     11 |      71 |      471 |        1471 |       471 |     5471 | 142 |  143 | LCAAAA   | OAAAAA   | OOOOxx
    5006 |      15 |   0 |    2 |   6 |      6 |       6 |        6 |        1006 |         6 |     5006 |  12 |   13 | OKAAAA   | PAAAAA   | VVVVxx
    5387 |      16 |   1 |    3 |   7 |      7 |      87 |      387 |        1387 |       387 |     5387 | 174 |  175 | FZAAAA   | QAAAAA   | AAAAxx
    5785 |      17 |   1 |    1 |   5 |      5 |      85 |      785 |        1785 |       785 |     5785 | 170 |  171 | NOAAAA   | RAAAAA   | HHHHxx
    6621 |      18 |   1 |    1 |   1 |      1 |      21 |      621 |         621 |      1621 |     6621 |  42 |   43 | RUAAAA   | SAAAAA   | OOOOxx
    6969 |      19 |   1 |    1 |   9 |      9 |      69 |      969 |         969 |      1969 |     6969 | 138 |  139 | BIAAAA   | TAAAAA   | VVVVxx
    9460 |      20 |   0 |    0 |   0 |      0 |      60 |      460 |        1460 |      4460 |     9460 | 120 |  121 | WZAAAA   | UAAAAA   | AAAAxx
363 364
(21 rows)

365 366 367
FETCH 22 in foo22;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
       3 |    5679 |   1 |    3 |   3 |      3 |       3 |        3 |           3 |         3 |        3 |   6 |    7 | DAAAAA   | LKIAAA   | VVVVxx
       4 |    1621 |   0 |    0 |   4 |      4 |       4 |        4 |           4 |         4 |        4 |   8 |    9 | EAAAAA   | JKCAAA   | HHHHxx
       5 |    5557 |   1 |    1 |   5 |      5 |       5 |        5 |           5 |         5 |        5 |  10 |   11 | FAAAAA   | TFIAAA   | HHHHxx
       6 |    2855 |   0 |    2 |   6 |      6 |       6 |        6 |           6 |         6 |        6 |  12 |   13 | GAAAAA   | VFEAAA   | VVVVxx
       7 |    8518 |   1 |    3 |   7 |      7 |       7 |        7 |           7 |         7 |        7 |  14 |   15 | HAAAAA   | QPMAAA   | OOOOxx
       8 |    5435 |   0 |    0 |   8 |      8 |       8 |        8 |           8 |         8 |        8 |  16 |   17 | IAAAAA   | BBIAAA   | VVVVxx
       9 |    4463 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |         9 |        9 |  18 |   19 | JAAAAA   | RPGAAA   | VVVVxx
      10 |    8788 |   0 |    2 |   0 |     10 |      10 |       10 |          10 |        10 |       10 |  20 |   21 | KAAAAA   | AANAAA   | AAAAxx
      11 |    8396 |   1 |    3 |   1 |     11 |      11 |       11 |          11 |        11 |       11 |  22 |   23 | LAAAAA   | YKMAAA   | AAAAxx
      12 |    6605 |   0 |    0 |   2 |     12 |      12 |       12 |          12 |        12 |       12 |  24 |   25 | MAAAAA   | BUJAAA   | HHHHxx
      13 |    5696 |   1 |    1 |   3 |     13 |      13 |       13 |          13 |        13 |       13 |  26 |   27 | NAAAAA   | CLIAAA   | AAAAxx
      14 |    4341 |   0 |    2 |   4 |     14 |      14 |       14 |          14 |        14 |       14 |  28 |   29 | OAAAAA   | ZKGAAA   | HHHHxx
      15 |    1358 |   1 |    3 |   5 |     15 |      15 |       15 |          15 |        15 |       15 |  30 |   31 | PAAAAA   | GACAAA   | OOOOxx
      16 |    9675 |   0 |    0 |   6 |     16 |      16 |       16 |          16 |        16 |       16 |  32 |   33 | QAAAAA   | DIOAAA   | VVVVxx
      17 |    8274 |   1 |    1 |   7 |     17 |      17 |       17 |          17 |        17 |       17 |  34 |   35 | RAAAAA   | GGMAAA   | OOOOxx
      18 |     376 |   0 |    2 |   8 |     18 |      18 |       18 |          18 |        18 |       18 |  36 |   37 | SAAAAA   | MOAAAA   | AAAAxx
      19 |    7303 |   1 |    3 |   9 |     19 |      19 |       19 |          19 |        19 |       19 |  38 |   39 | TAAAAA   | XUKAAA   | VVVVxx
      20 |    5574 |   0 |    0 |   0 |      0 |      20 |       20 |          20 |        20 |       20 |  40 |   41 | UAAAAA   | KGIAAA   | OOOOxx
      21 |    1628 |   1 |    1 |   1 |      1 |      21 |       21 |          21 |        21 |       21 |  42 |   43 | VAAAAA   | QKCAAA   | AAAAxx
390 391
(22 rows)

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
FETCH 23 in foo23;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
    1891 |       1 |   1 |    3 |   1 |     11 |      91 |      891 |        1891 |      1891 |     1891 | 182 |  183 | TUAAAA   | BAAAAA   | HHHHxx
    3420 |       2 |   0 |    0 |   0 |      0 |      20 |      420 |        1420 |      3420 |     3420 |  40 |   41 | OBAAAA   | CAAAAA   | OOOOxx
    9850 |       3 |   0 |    2 |   0 |     10 |      50 |      850 |        1850 |      4850 |     9850 | 100 |  101 | WOAAAA   | DAAAAA   | VVVVxx
    7164 |       4 |   0 |    0 |   4 |      4 |      64 |      164 |        1164 |      2164 |     7164 | 128 |  129 | OPAAAA   | EAAAAA   | AAAAxx
    8009 |       5 |   1 |    1 |   9 |      9 |       9 |        9 |           9 |      3009 |     8009 |  18 |   19 | BWAAAA   | FAAAAA   | HHHHxx
    5057 |       6 |   1 |    1 |   7 |     17 |      57 |       57 |        1057 |        57 |     5057 | 114 |  115 | NMAAAA   | GAAAAA   | OOOOxx
    6701 |       7 |   1 |    1 |   1 |      1 |       1 |      701 |         701 |      1701 |     6701 |   2 |    3 | TXAAAA   | HAAAAA   | VVVVxx
    4321 |       8 |   1 |    1 |   1 |      1 |      21 |      321 |         321 |      4321 |     4321 |  42 |   43 | FKAAAA   | IAAAAA   | AAAAxx
    3043 |       9 |   1 |    3 |   3 |      3 |      43 |       43 |        1043 |      3043 |     3043 |  86 |   87 | BNAAAA   | JAAAAA   | HHHHxx
    1314 |      10 |   0 |    2 |   4 |     14 |      14 |      314 |        1314 |      1314 |     1314 |  28 |   29 | OYAAAA   | KAAAAA   | OOOOxx
    1504 |      11 |   0 |    0 |   4 |      4 |       4 |      504 |        1504 |      1504 |     1504 |   8 |    9 | WFAAAA   | LAAAAA   | VVVVxx
    5222 |      12 |   0 |    2 |   2 |      2 |      22 |      222 |        1222 |       222 |     5222 |  44 |   45 | WSAAAA   | MAAAAA   | AAAAxx
    6243 |      13 |   1 |    3 |   3 |      3 |      43 |      243 |         243 |      1243 |     6243 |  86 |   87 | DGAAAA   | NAAAAA   | HHHHxx
    5471 |      14 |   1 |    3 |   1 |     11 |      71 |      471 |        1471 |       471 |     5471 | 142 |  143 | LCAAAA   | OAAAAA   | OOOOxx
    5006 |      15 |   0 |    2 |   6 |      6 |       6 |        6 |        1006 |         6 |     5006 |  12 |   13 | OKAAAA   | PAAAAA   | VVVVxx
    5387 |      16 |   1 |    3 |   7 |      7 |      87 |      387 |        1387 |       387 |     5387 | 174 |  175 | FZAAAA   | QAAAAA   | AAAAxx
    5785 |      17 |   1 |    1 |   5 |      5 |      85 |      785 |        1785 |       785 |     5785 | 170 |  171 | NOAAAA   | RAAAAA   | HHHHxx
    6621 |      18 |   1 |    1 |   1 |      1 |      21 |      621 |         621 |      1621 |     6621 |  42 |   43 | RUAAAA   | SAAAAA   | OOOOxx
    6969 |      19 |   1 |    1 |   9 |      9 |      69 |      969 |         969 |      1969 |     6969 | 138 |  139 | BIAAAA   | TAAAAA   | VVVVxx
    9460 |      20 |   0 |    0 |   0 |      0 |      60 |      460 |        1460 |      4460 |     9460 | 120 |  121 | WZAAAA   | UAAAAA   | AAAAxx
      59 |      21 |   1 |    3 |   9 |     19 |      59 |       59 |          59 |        59 |       59 | 118 |  119 | HCAAAA   | VAAAAA   | HHHHxx
    8020 |      22 |   0 |    0 |   0 |      0 |      20 |       20 |          20 |      3020 |     8020 |  40 |   41 | MWAAAA   | WAAAAA   | OOOOxx
418 419
(23 rows)

420 421 422 423 424 425 426 427 428 429 430 431
CLOSE foo1;
CLOSE foo2;
CLOSE foo3;
CLOSE foo4;
CLOSE foo5;
CLOSE foo6;
CLOSE foo7;
CLOSE foo8;
CLOSE foo9;
CLOSE foo10;
CLOSE foo11;
CLOSE foo12;
432
-- leave some cursors open, to test that auto-close works.
433 434
-- record this in the system view as well (don't query the time field there
-- however)
435
SELECT name, statement, is_holdable, is_binary, is_scrollable FROM pg_cursors ORDER BY 1;
436 437
 name  |                               statement                               | is_holdable | is_binary | is_scrollable 
-------+-----------------------------------------------------------------------+-------------+-----------+---------------
438
 foo13 | DECLARE foo13 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2; | f           | f         | f
439
 foo14 | DECLARE foo14 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;        | f           | f         | f
440
 foo15 | DECLARE foo15 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2; | f           | f         | f
441
 foo16 | DECLARE foo16 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;        | f           | f         | f
442 443
 foo17 | DECLARE foo17 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2; | f           | f         | f
 foo18 | DECLARE foo18 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;        | f           | f         | f
444
 foo19 | DECLARE foo19 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2; | f           | f         | f
445
 foo20 | DECLARE foo20 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;        | f           | f         | f
446
 foo21 | DECLARE foo21 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2; | f           | f         | f
447
 foo22 | DECLARE foo22 CURSOR FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;        | f           | f         | f
448
 foo23 | DECLARE foo23 SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2; | f           | f         | f
449 450
(11 rows)

451
END;
452 453 454 455 456
SELECT name, statement, is_holdable, is_binary, is_scrollable FROM pg_cursors;
 name | statement | is_holdable | is_binary | is_scrollable 
------+-----------+-------------+-----------+---------------
(0 rows)

457 458 459 460
--
-- NO SCROLL disallows backward fetching
--
BEGIN;
461
DECLARE foo24 NO SCROLL CURSOR FOR SELECT * FROM tenk1 ORDER BY unique2;
462 463 464 465 466 467 468
FETCH 1 FROM foo24;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
    8800 |       0 |   0 |    0 |   0 |      0 |       0 |      800 |         800 |      3800 |     8800 |   0 |    1 | MAAAAA   | AAAAAA   | AAAAxx
(1 row)

FETCH BACKWARD 1 FROM foo24; -- should fail
469
ERROR:  backward scan is not supported in this version of Greenplum Database
470 471 472 473
END;
--
-- Cursors outside transaction blocks
--
474
SELECT name, statement, is_holdable, is_binary, is_scrollable FROM pg_cursors;
475 476 477 478
 name | statement | is_holdable | is_binary | is_scrollable 
------+-----------+-------------+-----------+---------------
(0 rows)

479
BEGIN;
480
DECLARE foo25 CURSOR WITH HOLD FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4;
481 482 483
FETCH FROM foo25;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
484
       0 |    9998 |   0 |    0 |   0 |      0 |       0 |        0 |           0 |         0 |        0 |   0 |    1 | AAAAAA   | OUOAAA   | OOOOxx
485 486 487 488 489
(1 row)

FETCH FROM foo25;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
490
       1 |    2838 |   1 |    1 |   1 |      1 |       1 |        1 |           1 |         1 |        1 |   2 |    3 | BAAAAA   | EFEAAA   | OOOOxx
491 492 493 494 495 496
(1 row)

COMMIT;
FETCH FROM foo25;
 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
497
       2 |    2716 |   0 |    2 |   2 |      2 |       2 |        2 |           2 |         2 |        2 |   4 |    5 | CAAAAA   | MAEAAA   | AAAAxx
498 499
(1 row)

500 501
--FETCH BACKWARD FROM foo25;
--FETCH ABSOLUTE -1 FROM foo25;
502
SELECT name, statement, is_holdable, is_binary, is_scrollable FROM pg_cursors;
503 504 505
 name  |                                statement                                 | is_holdable | is_binary | is_scrollable 
-------+--------------------------------------------------------------------------+-------------+-----------+---------------
 foo25 | DECLARE foo25 CURSOR WITH HOLD FOR SELECT * FROM tenk2 ORDER BY 1,2,3,4; | t           | f         | f
506 507
(1 row)

508 509 510 511 512
CLOSE foo25;
--
-- ROLLBACK should close holdable cursors
--
BEGIN;
513
DECLARE foo26 CURSOR WITH HOLD FOR SELECT * FROM tenk1 ORDER BY unique2;
514 515 516
ROLLBACK;
-- should fail
FETCH FROM foo26;
517
ERROR:  cursor "foo26" does not exist
518 519 520 521 522 523 524
--
-- Parameterized DECLARE needs to insert param values into the cursor portal
--
BEGIN;
CREATE FUNCTION declares_cursor(text)
   RETURNS void
   AS 'DECLARE c CURSOR FOR SELECT stringu1 FROM tenk1 WHERE stringu1 LIKE $1;'
525
   LANGUAGE SQL READS SQL DATA;
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
SELECT declares_cursor('AB%');
 declares_cursor 
-----------------
 
(1 row)

FETCH ALL FROM c;
 stringu1 
----------
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
 ABAAAA
(15 rows)

ROLLBACK;
553 554 555 556 557 558
--
-- Test behavior of both volatile and stable functions inside a cursor;
-- in particular we want to see what happens during commit of a holdable
-- cursor
--
create temp table tt1(f1 int);
559 560
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'f1' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
561
create function count_tt1_v() returns int8 as
562
'select count(*) from tt1' language sql volatile READS SQL DATA;
563
create function count_tt1_s() returns int8 as
564
'select count(*) from tt1' language sql stable READS SQL DATA;
565 566 567 568
begin;
insert into tt1 values(1);
declare c1 cursor for select count_tt1_v(), count_tt1_s();
insert into tt1 values(2);
569 570
-- fetch all from c1; -- DISABLED: see open JIRA MPP-835
-- start_ignore
571 572 573 574
 count_tt1_v | count_tt1_s 
-------------+-------------
           2 |           1
(1 row)
575
-- end_ignore
576 577 578 579 580 581 582
rollback;
begin;
insert into tt1 values(1);
declare c2 cursor with hold for select count_tt1_v(), count_tt1_s();
insert into tt1 values(2);
commit;
delete from tt1;
583 584
-- fetch all from c2; -- DISABLED: see open JIRA MPP-835
-- start_ignore
585 586 587 588
 count_tt1_v | count_tt1_s 
-------------+-------------
           2 |           1
(1 row)
589
-- end_ignore
590 591
drop function count_tt1_v();
drop function count_tt1_s();
592 593
-- Create a cursor with the BINARY option and check the pg_cursors view
BEGIN;
594
SELECT name, statement, is_holdable, is_binary, is_scrollable FROM pg_cursors;
595 596 597 598 599 600
 name |                              statement                               | is_holdable | is_binary | is_scrollable 
------+----------------------------------------------------------------------+-------------+-----------+---------------
 c2   | declare c2 cursor with hold for select count_tt1_v(), count_tt1_s(); | t           | f         | f
(1 row)

DECLARE bc BINARY CURSOR FOR SELECT * FROM tenk1;
601
SELECT name, statement, is_holdable, is_binary, is_scrollable FROM pg_cursors;
602 603
 name |                              statement                               | is_holdable | is_binary | is_scrollable 
------+----------------------------------------------------------------------+-------------+-----------+---------------
604
 bc   | DECLARE bc BINARY CURSOR FOR SELECT * FROM tenk1;                    | f           | t         | f
605 606 607 608 609 610 611
 c2   | declare c2 cursor with hold for select count_tt1_v(), count_tt1_s(); | t           | f         | f
(2 rows)

ROLLBACK;
-- We should not see the portal that is created internally to
-- implement EXECUTE in pg_cursors
PREPARE cprep AS
612
  SELECT name, statement, is_holdable, is_binary, is_scrollable FROM pg_cursors;
613 614 615 616 617 618
EXECUTE cprep;
 name |                              statement                               | is_holdable | is_binary | is_scrollable 
------+----------------------------------------------------------------------+-------------+-----------+---------------
 c2   | declare c2 cursor with hold for select count_tt1_v(), count_tt1_s(); | t           | f         | f
(1 row)

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
-- test CLOSE ALL;
SELECT name FROM pg_cursors ORDER BY 1;
 name 
------
 c2
(1 row)

CLOSE ALL;
SELECT name FROM pg_cursors ORDER BY 1;
 name 
------
(0 rows)

BEGIN;
DECLARE foo1 CURSOR WITH HOLD FOR SELECT 1;
DECLARE foo2 CURSOR WITHOUT HOLD FOR SELECT 1;
SELECT name FROM pg_cursors ORDER BY 1;
 name 
------
 foo1
 foo2
(2 rows)

CLOSE ALL;
SELECT name FROM pg_cursors ORDER BY 1;
 name 
------
(0 rows)

COMMIT;
649 650 651
--
-- Tests for updatable cursors
--
652 653 654 655
-- In GPDB, we use a dummy column as distribution key, so that all the
-- rows land on the same segment. Otherwise the order the cursor returns
-- the rows is unstable.
CREATE TEMP TABLE uctest(f1 int, f2 text, distkey text) distributed by (distkey);
656
INSERT INTO uctest VALUES (1, 'one'), (2, 'two'), (3, 'three');
657
SELECT f1, f2 FROM uctest;
658 659 660 661 662 663 664 665 666
 f1 |  f2   
----+-------
  1 | one
  2 | two
  3 | three
(3 rows)

-- Check DELETE WHERE CURRENT
BEGIN;
667
DECLARE c1 CURSOR FOR SELECT f1, f2 FROM uctest;
668 669 670 671 672 673 674 675 676
FETCH 2 FROM c1;
 f1 | f2  
----+-----
  1 | one
  2 | two
(2 rows)

DELETE FROM uctest WHERE CURRENT OF c1;
-- should show deletion
677
SELECT f1, f2 FROM uctest;
678 679 680 681 682 683 684 685 686 687 688 689 690 691
 f1 |  f2   
----+-------
  1 | one
  3 | three
(2 rows)

-- cursor did not move
FETCH ALL FROM c1;
 f1 |  f2   
----+-------
  3 | three
(1 row)

-- cursor is insensitive
692 693
--MOVE BACKWARD ALL IN c1; -- backwards scans not supported in GPDB
--FETCH ALL FROM c1;
694 695
COMMIT;
-- should still see deletion
696
SELECT f1, f2 FROM uctest;
697 698 699 700 701 702 703 704
 f1 |  f2   
----+-------
  1 | one
  3 | three
(2 rows)

-- Check UPDATE WHERE CURRENT; this time use FOR UPDATE
BEGIN;
705
DECLARE c1 CURSOR FOR SELECT f1, f2 FROM uctest FOR UPDATE;
706 707 708 709 710 711 712
FETCH c1;
 f1 | f2  
----+-----
  1 | one
(1 row)

UPDATE uctest SET f1 = 8 WHERE CURRENT OF c1;
713
SELECT f1, f2 FROM uctest;
714 715 716 717 718 719 720
 f1 |  f2   
----+-------
  3 | three
  8 | one
(2 rows)

COMMIT;
721
SELECT f1, f2 FROM uctest;
722 723 724 725 726 727
 f1 |  f2   
----+-------
  3 | three
  8 | one
(2 rows)

728 729
-- Check repeated-update and update-then-delete cases
BEGIN;
730
DECLARE c1 CURSOR FOR SELECT f1, f2 FROM uctest;
731 732 733 734 735 736 737
FETCH c1;
 f1 |  f2   
----+-------
  3 | three
(1 row)

UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1;
738
SELECT f1, f2 FROM uctest;
739 740 741 742 743 744
 f1 |  f2   
----+-------
  8 | one
 13 | three
(2 rows)

745 746
UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1; -- currently broken on GPDB! (does nothing)
SELECT f1, f2 FROM uctest;
747 748 749
 f1 |  f2   
----+-------
  8 | one
750
 13 | three
751 752 753
(2 rows)

-- insensitive cursor should not show effects of updates or deletes
754 755 756
--FETCH RELATIVE 0 FROM c1;
DELETE FROM uctest WHERE CURRENT OF c1; -- currently broken on GPDB! (does nothing)
SELECT f1, f2 FROM uctest;
757
 f1 |  f2   
758
----+-------
759
  8 | one
760 761
 13 | three
(2 rows)
762 763

DELETE FROM uctest WHERE CURRENT OF c1; -- no-op
764
SELECT f1, f2 FROM uctest;
765
 f1 |  f2   
766
----+-------
767
  8 | one
768 769
 13 | three
(2 rows)
770 771

UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1; -- no-op
772
SELECT f1, f2 FROM uctest;
773 774
 f1 |  f2   
----+-------
775 776 777
  8 | one
 13 | three
(2 rows)
778

779
--FETCH RELATIVE 0 FROM c1;
780
ROLLBACK;
781
SELECT f1, f2 FROM uctest;
782 783 784 785 786 787 788
 f1 |  f2   
----+-------
  3 | three
  8 | one
(2 rows)

BEGIN;
789
DECLARE c1 CURSOR FOR SELECT f1, f2 FROM uctest FOR UPDATE;
790 791 792 793 794 795 796
FETCH c1;
 f1 |  f2   
----+-------
  3 | three
(1 row)

UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1;
797
SELECT f1, f2 FROM uctest;
798 799 800 801 802 803
 f1 |  f2   
----+-------
  8 | one
 13 | three
(2 rows)

804 805
UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1; -- currently broken on GPDB! (does nothing)
SELECT f1, f2 FROM uctest;
806 807 808
 f1 |  f2   
----+-------
  8 | one
809
 13 | three
810 811
(2 rows)

812 813
DELETE FROM uctest WHERE CURRENT OF c1; -- currently broken on GPDB! (does nothing)
SELECT f1, f2 FROM uctest;
814
 f1 |  f2   
815
----+-------
816
  8 | one
817 818
 13 | three
(2 rows)
819 820

DELETE FROM uctest WHERE CURRENT OF c1; -- no-op
821
SELECT f1, f2 FROM uctest;
822
 f1 |  f2   
823
----+-------
824
  8 | one
825 826
 13 | three
(2 rows)
827 828

UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1; -- no-op
829
SELECT f1, f2 FROM uctest;
830
 f1 |  f2   
831
----+-------
832
  8 | one
833 834
 13 | three
(2 rows)
835

836
--- sensitive cursors can't currently scroll back, so this is an error:
837
FETCH RELATIVE 0 FROM c1;
838 839
ERROR:  cursor can only scan forward
HINT:  Declare it with SCROLL option to enable backward scan.
840
ROLLBACK;
841
SELECT f1, f2 FROM uctest;
842 843 844 845 846 847
 f1 |  f2   
----+-------
  3 | three
  8 | one
(2 rows)

848 849
-- Check inheritance cases
CREATE TEMP TABLE ucchild () inherits (uctest);
850
NOTICE:  table has parent, setting distribution columns to match parent table
851
INSERT INTO ucchild values(100, 'hundred');
852
SELECT f1, f2 FROM uctest;
853 854 855 856 857 858 859 860
 f1  |   f2    
-----+---------
   3 | three
   8 | one
 100 | hundred
(3 rows)

BEGIN;
861
DECLARE c1 CURSOR FOR SELECT f1, f2 FROM uctest FOR UPDATE;
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
FETCH 1 FROM c1;
 f1 |  f2   
----+-------
  3 | three
(1 row)

UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1;
FETCH 1 FROM c1;
 f1 | f2  
----+-----
  8 | one
(1 row)

UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1;
FETCH 1 FROM c1;
 f1  |   f2    
-----+---------
 100 | hundred
(1 row)

UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1;
FETCH 1 FROM c1;
 f1 | f2 
----+----
(0 rows)

COMMIT;
889
SELECT f1, f2 FROM uctest;
890 891 892 893 894 895 896
 f1  |   f2    
-----+---------
  13 | three
  18 | one
 110 | hundred
(3 rows)

897 898 899 900
-- Can update from a self-join, but only if FOR UPDATE says which to use
BEGIN;
DECLARE c1 CURSOR FOR SELECT * FROM uctest a, uctest b WHERE a.f1 = b.f1 + 5;
FETCH 1 FROM c1;
901 902 903
 f1 | f2  | distkey | f1 |  f2   | distkey 
----+-----+---------+----+-------+---------
 18 | one |         | 13 | three | 
904 905 906 907 908 909 910 911
(1 row)

UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1;  -- fail
ERROR:  cursor "c1" is not a simply updatable scan of table "uctest"
ROLLBACK;
BEGIN;
DECLARE c1 CURSOR FOR SELECT * FROM uctest a, uctest b WHERE a.f1 = b.f1 + 5 FOR UPDATE;
FETCH 1 FROM c1;
912 913 914
 f1 | f2  | distkey | f1 |  f2   | distkey 
----+-----+---------+----+-------+---------
 18 | one |         | 13 | three | 
915 916 917
(1 row)

UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1;  -- fail
918
ERROR:  cursor "c1" is not a simply updatable scan of table "uctest"
919 920 921 922
ROLLBACK;
BEGIN;
DECLARE c1 CURSOR FOR SELECT * FROM uctest a, uctest b WHERE a.f1 = b.f1 + 5 FOR SHARE OF a;
FETCH 1 FROM c1;
923 924 925
 f1 | f2  | distkey | f1 |  f2   | distkey 
----+-----+---------+----+-------+---------
 18 | one |         | 13 | three | 
926 927 928
(1 row)

UPDATE uctest SET f1 = f1 + 10 WHERE CURRENT OF c1;
929
ERROR:  cursor "c1" is not a simply updatable scan of table "uctest"
930
SELECT * FROM uctest;
931
ERROR:  current transaction is aborted, commands ignored until end of transaction block
932
ROLLBACK;
933 934 935 936 937 938 939 940 941 942 943 944
-- Check various error cases
DELETE FROM uctest WHERE CURRENT OF c1;  -- fail, no such cursor
ERROR:  cursor "c1" does not exist
DECLARE cx CURSOR WITH HOLD FOR SELECT * FROM uctest;
DELETE FROM uctest WHERE CURRENT OF cx;  -- fail, can't use held cursor
ERROR:  cursor "cx" is held from a previous transaction
BEGIN;
DECLARE c CURSOR FOR SELECT * FROM tenk2;
DELETE FROM uctest WHERE CURRENT OF c;  -- fail, cursor on wrong table
ERROR:  cursor "c" is not a simply updatable scan of table "uctest"
ROLLBACK;
BEGIN;
945 946
DECLARE c CURSOR FOR SELECT * FROM tenk2 FOR SHARE;
DELETE FROM uctest WHERE CURRENT OF c;  -- fail, cursor on wrong table
947
ERROR:  cursor "c" is not a simply updatable scan of table "uctest"
948 949
ROLLBACK;
BEGIN;
950 951 952 953 954 955 956 957 958 959 960 961 962 963
DECLARE c CURSOR FOR SELECT * FROM tenk1 JOIN tenk2 USING (unique1);
DELETE FROM tenk1 WHERE CURRENT OF c;  -- fail, cursor is on a join
ERROR:  cursor "c" is not a simply updatable scan of table "tenk1"
ROLLBACK;
BEGIN;
DECLARE c CURSOR FOR SELECT f1,count(*) FROM uctest GROUP BY f1;
DELETE FROM uctest WHERE CURRENT OF c;  -- fail, cursor is on aggregation
ERROR:  cursor "c" is not a simply updatable scan of table "uctest"
ROLLBACK;
BEGIN;
DECLARE c1 CURSOR FOR SELECT * FROM uctest;
DELETE FROM uctest WHERE CURRENT OF c1; -- fail, no current row
ERROR:  cursor "c1" is not positioned on a row
ROLLBACK;
964 965 966 967
BEGIN;
DECLARE c1 CURSOR FOR SELECT MIN(f1) FROM uctest FOR UPDATE;
ERROR:  FOR UPDATE is not allowed with aggregate functions
ROLLBACK;
968 969
-- WHERE CURRENT OF may someday work with views, but today is not that day.
-- For now, just make sure it errors out cleanly.
970
CREATE TEMP VIEW ucview AS SELECT f1, f2 FROM uctest;
971 972 973 974 975 976 977 978 979 980 981 982 983
CREATE RULE ucrule AS ON DELETE TO ucview DO INSTEAD
  DELETE FROM uctest WHERE f1 = OLD.f1;
BEGIN;
DECLARE c1 CURSOR FOR SELECT * FROM ucview;
FETCH FROM c1;
 f1 |  f2   
----+-------
 13 | three
(1 row)

DELETE FROM ucview WHERE CURRENT OF c1; -- fail, views not supported
ERROR:  WHERE CURRENT OF on a view is not implemented
ROLLBACK;
984 985 986 987
-- Check cursors for functions.
BEGIN;
DECLARE c1 CURSOR FOR SELECT * FROM LOWER('TEST');
FETCH ALL FROM c1;
988
 lower 
989 990 991 992 993
-------
 test
(1 row)

COMMIT;
994 995 996 997 998 999
-- Check WHERE CURRENT OF with an index-only scan
BEGIN;
EXPLAIN (costs off)
DECLARE c1 CURSOR FOR SELECT stringu1 FROM onek WHERE stringu1 = 'DZAAAA';
                 QUERY PLAN                  
---------------------------------------------
1000 1001 1002
 Gather Motion 3:1  (slice1; segments: 3)
   ->  Seq Scan on onek
         Filter: (stringu1 = 'DZAAAA'::name)
1003
 Optimizer: Postgres query optimizer
1004
(4 rows)
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018

DECLARE c1 CURSOR FOR SELECT stringu1 FROM onek WHERE stringu1 = 'DZAAAA';
FETCH FROM c1;
 stringu1 
----------
 DZAAAA
(1 row)

DELETE FROM onek WHERE CURRENT OF c1;
SELECT stringu1 FROM onek WHERE stringu1 = 'DZAAAA';
 stringu1 
----------
(0 rows)

1019
ROLLBACK;
1020 1021
-- start_ignore
-- ignore the block, because cursor can only scan forward
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
-- Check behavior with rewinding to a previous child scan node,
-- as per bug #15395
BEGIN;
CREATE TABLE current_check (currentid int, payload text);
CREATE TABLE current_check_1 () INHERITS (current_check);
CREATE TABLE current_check_2 () INHERITS (current_check);
INSERT INTO current_check_1 SELECT i, 'p' || i FROM generate_series(1,9) i;
INSERT INTO current_check_2 SELECT i, 'P' || i FROM generate_series(10,19) i;
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM current_check;
-- This tests the fetch-backwards code path
FETCH ABSOLUTE 12 FROM c1;
 currentid | payload 
-----------+---------
        12 | P12
(1 row)

FETCH ABSOLUTE 8 FROM c1;
 currentid | payload 
-----------+---------
         8 | p8
(1 row)

DELETE FROM current_check WHERE CURRENT OF c1 RETURNING *;
 currentid | payload 
-----------+---------
         8 | p8
(1 row)

-- This tests the ExecutorRewind code path
FETCH ABSOLUTE 13 FROM c1;
 currentid | payload 
-----------+---------
        13 | P13
(1 row)

FETCH ABSOLUTE 1 FROM c1;
 currentid | payload 
-----------+---------
         1 | p1
(1 row)

DELETE FROM current_check WHERE CURRENT OF c1 RETURNING *;
 currentid | payload 
-----------+---------
         1 | p1
(1 row)

SELECT * FROM current_check;
 currentid | payload 
-----------+---------
         2 | p2
         3 | p3
         4 | p4
         5 | p5
         6 | p6
         7 | p7
         9 | p9
        10 | P10
        11 | P11
        12 | P12
        13 | P13
        14 | P14
        15 | P15
        16 | P16
        17 | P17
        18 | P18
        19 | P19
(17 rows)

1091
ROLLBACK;
1092
-- end_ignore
1093 1094
-- Make sure snapshot management works okay, per bug report in
-- 235395b90909301035v7228ce63q392931f15aa74b31@mail.gmail.com
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
-- GPDB_90_MERGE_FIXME: This doesn't work correctly. Two issues:
-- 1. In GPDB, an UPDATE, or FOR UPDATE, locks the whole table. Because of
--    that, there cannot be concurrent updates, and we don't bother with
--    LockRows nodes in FOR UPDATE plans. However, in the upstream, the
--    LockRows node also handles fetching the latest tuple version, if it
--    was updated in the same transaction, by a *later* command.
--
-- 2. Even if we had LockRows in the plan, it still wouldn't work, at least
--    not always. In PostgreSQL, the LockRows node checks the visibility
--    when a row is FETCHed. Not before that. So if a row is UPDATEd in
--    the same transaction, before it's FETCHed, the FETCH is supposed to
--    see the effects of the UPDATE. In GPDB, however, a cursor starts
--    executing in the segments, as soon as the DECLARE CURSOR is issued,
--    so there's a race condition.
1109 1110
BEGIN;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
A
Asim R P 已提交
1111 1112
CREATE TABLE cursor (a int, b int);
INSERT INTO cursor VALUES (1, 1);
1113
DECLARE c1 NO SCROLL CURSOR FOR SELECT * FROM cursor FOR UPDATE;
A
Asim R P 已提交
1114
UPDATE cursor SET b = 2;
1115
FETCH ALL FROM c1;
1116 1117 1118 1119
 a | b 
---+---
 1 | 1
(1 row)
1120

1121
COMMIT;
1122
DROP TABLE cursor;
1123 1124
-- Check rewinding a cursor containing a stable function in LIMIT,
-- per bug report in 8336843.9833.1399385291498.JavaMail.root@quick
1125 1126 1127 1128 1129 1130
-- GPDB: ignore the result of the FETCH, because the order the rows
-- arrive from the segments is arbitrary in GPDB. This test isn't
-- very useful in GPDB anyway, as the bug that this was testing
-- happened when rewinding the cursor, and GPDB doesn't support
-- MOVE BACKWARD at all. But doesn't hurt to keep it to the extent
-- we can, I guess..
1131 1132 1133 1134
begin;
create function nochange(int) returns int
  as 'select $1 limit 1' language sql stable;
declare c cursor for select * from int8_tbl limit nochange(3);
1135
-- start_ignore
1136 1137 1138 1139 1140 1141 1142 1143
fetch all from c;
        q1        |        q2        
------------------+------------------
              123 |              456
              123 | 4567890123456789
 4567890123456789 |              123
(3 rows)

1144
-- end_ignore
1145
move backward all in c;
1146
ERROR:  backward scan is not supported in this version of Greenplum Database
1147
fetch all from c;
1148
ERROR:  current transaction is aborted, commands ignored until end of transaction block
1149
rollback;