~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/test/regress/expected/aggregates.out

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- AGGREGATES
 
3
--
 
4
SELECT avg(four) AS avg_1 FROM onek;
 
5
       avg_1        
 
6
--------------------
 
7
 1.5000000000000000
 
8
(1 row)
 
9
 
 
10
SELECT avg(a) AS avg_32 FROM aggtest WHERE a < 100;
 
11
       avg_32        
 
12
---------------------
 
13
 32.6666666666666667
 
14
(1 row)
 
15
 
 
16
-- In 7.1, avg(float4) is computed using float8 arithmetic.
 
17
-- Round the result to 3 digits to avoid platform-specific results.
 
18
SELECT avg(b)::numeric(10,3) AS avg_107_943 FROM aggtest;
 
19
 avg_107_943 
 
20
-------------
 
21
     107.943
 
22
(1 row)
 
23
 
 
24
SELECT avg(gpa) AS avg_3_4 FROM ONLY student;
 
25
 avg_3_4 
 
26
---------
 
27
     3.4
 
28
(1 row)
 
29
 
 
30
SELECT sum(four) AS sum_1500 FROM onek;
 
31
 sum_1500 
 
32
----------
 
33
     1500
 
34
(1 row)
 
35
 
 
36
SELECT sum(a) AS sum_198 FROM aggtest;
 
37
 sum_198 
 
38
---------
 
39
     198
 
40
(1 row)
 
41
 
 
42
SELECT sum(b) AS avg_431_773 FROM aggtest;
 
43
 avg_431_773 
 
44
-------------
 
45
     431.773
 
46
(1 row)
 
47
 
 
48
SELECT sum(gpa) AS avg_6_8 FROM ONLY student;
 
49
 avg_6_8 
 
50
---------
 
51
     6.8
 
52
(1 row)
 
53
 
 
54
SELECT max(four) AS max_3 FROM onek;
 
55
 max_3 
 
56
-------
 
57
     3
 
58
(1 row)
 
59
 
 
60
SELECT max(a) AS max_100 FROM aggtest;
 
61
 max_100 
 
62
---------
 
63
     100
 
64
(1 row)
 
65
 
 
66
SELECT max(aggtest.b) AS max_324_78 FROM aggtest;
 
67
 max_324_78 
 
68
------------
 
69
     324.78
 
70
(1 row)
 
71
 
 
72
SELECT max(student.gpa) AS max_3_7 FROM student;
 
73
 max_3_7 
 
74
---------
 
75
     3.7
 
76
(1 row)
 
77
 
 
78
SELECT count(four) AS cnt_1000 FROM onek;
 
79
 cnt_1000 
 
80
----------
 
81
     1000
 
82
(1 row)
 
83
 
 
84
SELECT count(DISTINCT four) AS cnt_4 FROM onek;
 
85
 cnt_4 
 
86
-------
 
87
     4
 
88
(1 row)
 
89
 
 
90
select ten, count(*), sum(four) from onek
 
91
group by ten order by ten;
 
92
 ten | count | sum 
 
93
-----+-------+-----
 
94
   0 |   100 | 100
 
95
   1 |   100 | 200
 
96
   2 |   100 | 100
 
97
   3 |   100 | 200
 
98
   4 |   100 | 100
 
99
   5 |   100 | 200
 
100
   6 |   100 | 100
 
101
   7 |   100 | 200
 
102
   8 |   100 | 100
 
103
   9 |   100 | 200
 
104
(10 rows)
 
105
 
 
106
select ten, count(four), sum(DISTINCT four) from onek
 
107
group by ten order by ten;
 
108
 ten | count | sum 
 
109
-----+-------+-----
 
110
   0 |   100 |   2
 
111
   1 |   100 |   4
 
112
   2 |   100 |   2
 
113
   3 |   100 |   4
 
114
   4 |   100 |   2
 
115
   5 |   100 |   4
 
116
   6 |   100 |   2
 
117
   7 |   100 |   4
 
118
   8 |   100 |   2
 
119
   9 |   100 |   4
 
120
(10 rows)
 
121
 
 
122
SELECT newavg(four) AS avg_1 FROM onek;
 
123
       avg_1        
 
124
--------------------
 
125
 1.5000000000000000
 
126
(1 row)
 
127
 
 
128
SELECT newsum(four) AS sum_1500 FROM onek;
 
129
 sum_1500 
 
130
----------
 
131
     1500
 
132
(1 row)
 
133
 
 
134
SELECT newcnt(four) AS cnt_1000 FROM onek;
 
135
 cnt_1000 
 
136
----------
 
137
     1000
 
138
(1 row)
 
139
 
 
140
-- test for outer-level aggregates
 
141
-- this should work
 
142
select ten, sum(distinct four) from onek a
 
143
group by ten
 
144
having exists (select 1 from onek b where sum(distinct a.four) = b.four);
 
145
 ten | sum 
 
146
-----+-----
 
147
   0 |   2
 
148
   2 |   2
 
149
   4 |   2
 
150
   6 |   2
 
151
   8 |   2
 
152
(5 rows)
 
153
 
 
154
-- this should fail because subquery has an agg of its own in WHERE
 
155
select ten, sum(distinct four) from onek a
 
156
group by ten
 
157
having exists (select 1 from onek b
 
158
               where sum(distinct a.four + b.four) = b.four);
 
159
ERROR:  aggregates not allowed in WHERE clause
 
160
--
 
161
-- test for bitwise integer aggregates
 
162
--
 
163
CREATE TEMPORARY TABLE bitwise_test(
 
164
  i2 INT2,
 
165
  i4 INT4,
 
166
  i8 INT8,
 
167
  i INTEGER,
 
168
  x INT2,
 
169
  y BIT(4)
 
170
);
 
171
-- empty case
 
172
SELECT 
 
173
  BIT_AND(i2) AS "?",
 
174
  BIT_OR(i4)  AS "?"
 
175
FROM bitwise_test;
 
176
 ? | ? 
 
177
---+---
 
178
   |  
 
179
(1 row)
 
180
 
 
181
COPY bitwise_test FROM STDIN NULL 'null';
 
182
SELECT
 
183
  BIT_AND(i2) AS "1",
 
184
  BIT_AND(i4) AS "1",
 
185
  BIT_AND(i8) AS "1",
 
186
  BIT_AND(i)  AS "?",
 
187
  BIT_AND(x)  AS "0",
 
188
  BIT_AND(y)  AS "0100",
 
189
  BIT_OR(i2)  AS "7",
 
190
  BIT_OR(i4)  AS "7",
 
191
  BIT_OR(i8)  AS "7",
 
192
  BIT_OR(i)   AS "?",
 
193
  BIT_OR(x)   AS "7",
 
194
  BIT_OR(y)   AS "1101"
 
195
FROM bitwise_test;
 
196
 1 | 1 | 1 | ? | 0 | 0100 | 7 | 7 | 7 | ? | 7 | 1101 
 
197
---+---+---+---+---+------+---+---+---+---+---+------
 
198
 1 | 1 | 1 | 1 | 0 | 0100 | 7 | 7 | 7 | 3 | 7 | 1101
 
199
(1 row)
 
200
 
 
201
--
 
202
-- test boolean aggregates
 
203
--
 
204
-- first test all possible transition and final states
 
205
SELECT
 
206
  -- boolean and transitions
 
207
  -- null because strict
 
208
  booland_statefunc(NULL, NULL)  IS NULL AS "t",
 
209
  booland_statefunc(TRUE, NULL)  IS NULL AS "t",
 
210
  booland_statefunc(FALSE, NULL) IS NULL AS "t",
 
211
  booland_statefunc(NULL, TRUE)  IS NULL AS "t",
 
212
  booland_statefunc(NULL, FALSE) IS NULL AS "t",
 
213
  -- and actual computations
 
214
  booland_statefunc(TRUE, TRUE) AS "t",
 
215
  NOT booland_statefunc(TRUE, FALSE) AS "t",
 
216
  NOT booland_statefunc(FALSE, TRUE) AS "t",
 
217
  NOT booland_statefunc(FALSE, FALSE) AS "t";
 
218
 t | t | t | t | t | t | t | t | t 
 
219
---+---+---+---+---+---+---+---+---
 
220
 t | t | t | t | t | t | t | t | t
 
221
(1 row)
 
222
 
 
223
SELECT
 
224
  -- boolean or transitions
 
225
  -- null because strict
 
226
  boolor_statefunc(NULL, NULL)  IS NULL AS "t",
 
227
  boolor_statefunc(TRUE, NULL)  IS NULL AS "t",
 
228
  boolor_statefunc(FALSE, NULL) IS NULL AS "t",
 
229
  boolor_statefunc(NULL, TRUE)  IS NULL AS "t",
 
230
  boolor_statefunc(NULL, FALSE) IS NULL AS "t",
 
231
  -- actual computations
 
232
  boolor_statefunc(TRUE, TRUE) AS "t",
 
233
  boolor_statefunc(TRUE, FALSE) AS "t",
 
234
  boolor_statefunc(FALSE, TRUE) AS "t",
 
235
  NOT boolor_statefunc(FALSE, FALSE) AS "t";
 
236
 t | t | t | t | t | t | t | t | t 
 
237
---+---+---+---+---+---+---+---+---
 
238
 t | t | t | t | t | t | t | t | t
 
239
(1 row)
 
240
 
 
241
CREATE TEMPORARY TABLE bool_test(  
 
242
  b1 BOOL,
 
243
  b2 BOOL,
 
244
  b3 BOOL,
 
245
  b4 BOOL);
 
246
-- empty case
 
247
SELECT
 
248
  BOOL_AND(b1)   AS "n",
 
249
  BOOL_OR(b3)    AS "n"
 
250
FROM bool_test;
 
251
 n | n 
 
252
---+---
 
253
   | 
 
254
(1 row)
 
255
 
 
256
COPY bool_test FROM STDIN NULL 'null';
 
257
SELECT
 
258
  BOOL_AND(b1)     AS "f",
 
259
  BOOL_AND(b2)     AS "t",
 
260
  BOOL_AND(b3)     AS "f",
 
261
  BOOL_AND(b4)     AS "n",
 
262
  BOOL_AND(NOT b2) AS "f",
 
263
  BOOL_AND(NOT b3) AS "t"
 
264
FROM bool_test;
 
265
 f | t | f | n | f | t 
 
266
---+---+---+---+---+---
 
267
 f | t | f |   | f | t
 
268
(1 row)
 
269
 
 
270
SELECT
 
271
  EVERY(b1)     AS "f",
 
272
  EVERY(b2)     AS "t",
 
273
  EVERY(b3)     AS "f",
 
274
  EVERY(b4)     AS "n",
 
275
  EVERY(NOT b2) AS "f",
 
276
  EVERY(NOT b3) AS "t"
 
277
FROM bool_test;
 
278
 f | t | f | n | f | t 
 
279
---+---+---+---+---+---
 
280
 f | t | f |   | f | t
 
281
(1 row)
 
282
 
 
283
SELECT
 
284
  BOOL_OR(b1)      AS "t",
 
285
  BOOL_OR(b2)      AS "t",
 
286
  BOOL_OR(b3)      AS "f",
 
287
  BOOL_OR(b4)      AS "n",
 
288
  BOOL_OR(NOT b2)  AS "f",
 
289
  BOOL_OR(NOT b3)  AS "t"
 
290
FROM bool_test;
 
291
 t | t | f | n | f | t 
 
292
---+---+---+---+---+---
 
293
 t | t | f |   | f | t
 
294
(1 row)
 
295