blob: d6e62627f2fd5be490b08a83722bafd20c1624c2 [file] [log] [blame]
create table dtype
(tint2 int2[],
tint4 int4[],
tint8 int8[],
tfloat4 float4[],
tfloat8 float8[],
tnumeric numeric[])
Distributed randomly;
insert into dtype values(
array[1, 2, 3],
array[1, 2, 3],
array[1, 2, 3],
array[1.1, 2.2, 3.3],
array[1.1, 2.2, 3.3],
array[1.1, 2.2, 3.3]
);
insert into dtype values(
array[5, 4, 3],
array[5, 4, 3],
array[5, 4, 3],
array[5.1, 4.2, 3.3],
array[5.1, 4.2, 3.3],
array[5.1, 4.2, 3.3]
);
select sum(tint2) from dtype;
sum
---------
{6,6,6}
(1 row)
select sum(tint4) from dtype;
sum
---------
{6,6,6}
(1 row)
select sum(tint8) from dtype;
sum
---------
{6,6,6}
(1 row)
select sum(tfloat4) from dtype;
sum
----------------------------------------------------------
{6.199999928474426,6.3999998569488525,6.599999904632568}
(1 row)
select sum(tfloat8) from dtype;
sum
-----------------------------
{6.199999999999999,6.4,6.6}
(1 row)
select sum(tnumeric) from dtype;
sum
-----------------------------
{6.199999999999999,6.4,6.6}
(1 row)
-- should be able to handle null values during sumation
insert into dtype values(null, null, null, null, null, null);
select sum(tint2) from dtype;
sum
---------
{6,6,6}
(1 row)
select sum(tint4) from dtype;
sum
---------
{6,6,6}
(1 row)
select sum(tint8) from dtype;
sum
---------
{6,6,6}
(1 row)
select sum(tfloat4) from dtype;
sum
----------------------------------------------------------
{6.199999928474426,6.3999998569488525,6.599999904632568}
(1 row)
select sum(tfloat8) from dtype;
sum
-----------------------------
{6.199999999999999,6.4,6.6}
(1 row)
select sum(tnumeric) from dtype;
sum
-----------------------------
{6.199999999999999,6.4,6.6}
(1 row)
-- these should fail, but tell us what the return type of sum() was
select sum(tint2)::boolean[] from dtype; -- bigint[]
ERROR: cannot cast type bigint[] to boolean[]
LINE 1: select sum(tint2)::boolean[] from dtype;
^
select sum(tint4)::boolean[] from dtype; -- bigint[]
ERROR: cannot cast type bigint[] to boolean[]
LINE 1: select sum(tint4)::boolean[] from dtype;
^
select sum(tint8)::boolean[] from dtype; -- bigint[]
ERROR: cannot cast type bigint[] to boolean[]
LINE 1: select sum(tint8)::boolean[] from dtype;
^
select sum(tfloat4)::boolean[] from dtype; -- float8[]
ERROR: cannot cast type double precision[] to boolean[]
LINE 1: select sum(tfloat4)::boolean[] from dtype;
^
select sum(tfloat8)::boolean[] from dtype; -- float8[]
ERROR: cannot cast type double precision[] to boolean[]
LINE 1: select sum(tfloat8)::boolean[] from dtype;
^
select sum(tnumeric)::boolean[] from dtype; -- float8[]
ERROR: cannot cast type double precision[] to boolean[]
LINE 1: select sum(tnumeric)::boolean[] from dtype;
^
-- What would normal sum do?
select sum(tint2[1])::boolean from dtype; -- bigint
ERROR: cannot cast type bigint to boolean
LINE 1: select sum(tint2[1])::boolean from dtype;
^
select sum(tint4[1])::boolean from dtype; -- bigint
ERROR: cannot cast type bigint to boolean
LINE 1: select sum(tint4[1])::boolean from dtype;
^
select sum(tint8[1])::boolean from dtype; -- numeric (bigint above)
ERROR: cannot cast type numeric to boolean
LINE 1: select sum(tint8[1])::boolean from dtype;
^
select sum(tfloat4[1])::boolean from dtype; -- float4 (float8 above)
ERROR: cannot cast type real to boolean
LINE 1: select sum(tfloat4[1])::boolean from dtype;
^
select sum(tfloat8[1])::boolean from dtype; -- float8
ERROR: cannot cast type double precision to boolean
LINE 1: select sum(tfloat8[1])::boolean from dtype;
^
select sum(tnumeric[1])::boolean from dtype; -- numeric
ERROR: cannot cast type numeric to boolean
LINE 1: select sum(tnumeric[1])::boolean from dtype;
^