set timezone='UTC'; create extension if not exists timescaledb; drop table if exists tsn_ns16 cascade; create table tsn_ns16(t ns16 not null, v int); select create_hypertable('tsn_ns16', by_range('t', 86400000000000)); select create_hypertable('tsn_ns16', by_range('t', 86400000000000, partition_func => 'ns16_part')); insert into tsn_ns16 select x::bigint::ns16, i from unnest(array[-305164800000000000,-43200000000000,0,1704067200123456789,1704175200000000000,1704261600000000000]) with ordinality u(x,i); insert into tsn_ns16 values ('-62135596800.000000000',7),('253402300799.999999999',8); select chunk_name, range_start_integer, range_end_integer from timescaledb_information.chunks where hypertable_name='tsn_ns16' order by 2; explain (costs off) select * from tsn_ns16 where t >= 1704153600000000000::bigint::ns16 and t < 1704240000000000000::bigint::ns16; select time_bucket(86400000000000::bigint, t) from tsn_ns16 limit 1; select time_bucket(86400000000000::bigint, ns16_part(t)) b, count(*) from tsn_ns16 group by 1 order by 1; alter table tsn_ns16 set (timescaledb.compress, timescaledb.compress_segmentby='v', timescaledb.compress_orderby='t desc'); select count(compress_chunk(c)) from show_chunks('tsn_ns16') c; select v from tsn_ns16 order by t; explain (costs off) select * from tsn_ns16 where t >= 1704153600000000000::bigint::ns16 and t < 1704240000000000000::bigint::ns16; create table tsn2_ns16(t ns16 not null, v int); select create_hypertable('tsn2_ns16', by_range('t', 86400000000000, partition_func => 'ns16_part')); insert into tsn2_ns16 select * from tsn_ns16; alter table tsn2_ns16 set (timescaledb.compress, timescaledb.compress_segmentby='t'); select count(compress_chunk(c)) from show_chunks('tsn2_ns16') c; create materialized view ca_ns16 with (timescaledb.continuous) as select time_bucket(86400000000000::bigint, ns16_part(t)) b, count(*) from tsn_ns16 group by 1; select set_integer_now_func('tsn_ns16','clock_ns'); select drop_chunks('tsn_ns16', older_than => 0::bigint); select count(*) from timescaledb_information.chunks where hypertable_name='tsn_ns16'; select add_retention_policy('tsn_ns16', drop_after => 86400000000000*365);