Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TYPE test_item AS
- (
- id INTEGER,
- duration INTEGER
- );
- SELECT run_command_on_workers($cmd$CREATE TYPE test_item AS
- (
- id INTEGER,
- duration INTEGER
- );$cmd$);
- CREATE TABLE test_count_distinct_array (key int, value int , value_arr test_item[]);
- SELECT create_distributed_table('test_count_distinct_array', 'key');
- INSERT INTO test_count_distinct_array SELECT i, i, ARRAY[(i,i)::test_item] FROM generate_Series(0, 1000) i;
- SELECT
- key,
- count(DISTINCT value),
- count(DISTINCT (item)."id"),
- count(DISTINCT (item)."id" * 3)
- FROM
- (
- SELECT key, unnest(value_arr) as item, value FROM test_count_distinct_array
- ) as sub
- GROUP BY 1
- ORDER BY 1 DESC
- LIMIT 5;
- SELECT user_id,
- count(sub.a::int),
- count(DISTINCT sub.a::int),
- count(DISTINCT (sub).a)
- FROM
- (SELECT user_id,
- unnnest(ARRAY[user_id * 1.5])a,
- random() b
- FROM users_table
- ) sub
- GROUP BY 1
- ORDER BY 1 DESC
- LIMIT 5;
Add Comment
Please, Sign In to add comment