\set ECHO none -- int SELECT count_distinct(x::int) FROM test_data_1_1000; count_distinct ---------------- 1000 (1 row) SELECT count_distinct(mod(x,10)::int) FROM test_data_1_1000; count_distinct ---------------- 10 (1 row) -- bigint SELECT count_distinct(x::bigint) FROM test_data_1_1000; count_distinct ---------------- 1000 (1 row) SELECT count_distinct(mod(x,10)::bigint) FROM test_data_1_1000; count_distinct ---------------- 10 (1 row) -- timestamp select count_distinct(now()::timestamp + (x || ' days')::interval) from test_data_1_1000; count_distinct ---------------- 1000 (1 row) select count_distinct(now() + (x || ' days')::interval) from test_data_1_1000; count_distinct ---------------- 1000 (1 row) -- bool select count_distinct(x::bool) from test_data_0_1000; count_distinct ---------------- 2 (1 row) -- int2 select count_distinct(x::int2) from test_data_1_1000; count_distinct ---------------- 1000 (1 row) -- array of int SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[x::int, (x+1)::int] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- 1001 (1 row) SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[mod(x,10)::int, mod(x+1,10)::int] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- 10 (1 row) -- array of bigint SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[x::bigint, (x+1)::bigint] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- 1001 (1 row) SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[mod(x,10)::bigint, mod(x+1,10)::bigint] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- 10 (1 row) -- array of timestamp SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[now()::timestamp + (x || ' days')::interval, now()::timestamp + ((x + 1) || ' days')::interval] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- 1001 (1 row) SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[now() + (x || ' days')::interval, now() + ((x + 1) || ' days')::interval] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- 1001 (1 row) -- array of bool SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[x::bool, (x+1)::bool] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- 1 (1 row) SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[mod(x,10)::bool, mod(x+1,10)::bool] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- 2 (1 row) -- array of int2 with nulls SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[NULL, NULL, NULL, NULL]::int2[] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- (1 row) SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[[NULL, x::int2, NULL], [NULL, (x+1)::int2, NULL]] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- 1001 (1 row) SELECT count_distinct_elements(z) FROM ( SELECT ARRAY[mod(x,10)::int2, mod(x+1,10)::int2] AS z FROM generate_series(1,1000) s(x) ) foo; count_distinct_elements ------------------------- 10 (1 row) ROLLBACK;