timescaledb/tsl/test/expected/compressed_collation.out
Bharathy b869f91e25 Show warnings during create_hypertable().
The schema of base table on which hypertables are created, should define
columns with proper data types. As per postgres best practices Wiki
(https://wiki.postgresql.org/wiki/Don't_Do_This), one should not define
columns with CHAR, VARCHAR, VARCHAR(N), instead use TEXT data type.
Similarly instead of using timestamp, one should use timestamptz.
This patch reports a WARNING to end user when creating hypertables,
if underlying parent table, has columns of above mentioned data types.

Fixes #4335
2022-09-12 18:47:47 +05:30

60 lines
2.6 KiB
Plaintext

-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
\c :TEST_DBNAME :ROLE_SUPERUSER
-- We have different collation names such as en_US, en-US-x-icu and so on,
-- that are available on different platforms.
select * from (
select 3 priority, 'en_US' "COLLATION"
union all (select 2, collname from pg_collation where collname ilike 'en_us%' order by collname limit 1)
union all (select 1, collname from pg_collation where collname ilike 'en_us_utf%8%' order by collname limit 1)
) c
order by priority limit 1 \gset
create table compressed_collation_ht(time timestamp, name text collate :"COLLATION",
value float);
select create_hypertable('compressed_collation_ht', 'time');
WARNING: column type "timestamp without time zone" used for "time" does not follow best practices
NOTICE: adding not-null constraint to column "time"
create_hypertable
--------------------------------------
(1,public,compressed_collation_ht,t)
(1 row)
alter table compressed_collation_ht set (timescaledb.compress,
timescaledb.compress_segmentby = 'name', timescaledb.compress_orderby = 'time');
insert into compressed_collation_ht values ('2021-01-01 01:01:01', 'á', '1'),
('2021-01-01 01:01:02', 'b', '2'), ('2021-01-01 01:01:03', 'ç', '2');
select 1 from (
select compress_chunk(chunk_schema || '.' || chunk_name)
from timescaledb_information.chunks
where hypertable_name = 'compressed_collation_ht'
) t;
?column?
----------
1
(1 row)
select ht.schema_name || '.' || ht.table_name as "CHUNK"
from _timescaledb_catalog.hypertable ht
inner join _timescaledb_catalog.hypertable ht2
on ht.id = ht2.compressed_hypertable_id
and ht2.table_name = 'compressed_collation_ht' \gset
create index on :CHUNK (name);
set enable_seqscan to off;
explain (costs off)
select * from compressed_collation_ht order by name;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------
Custom Scan (DecompressChunk) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk__compressed_hypertable_2_name_idx on compress_hyper_2_2_chunk
(2 rows)
select * from compressed_collation_ht order by name;
time | name | value
--------------------------+------+-------
Fri Jan 01 01:01:01 2021 | á | 1
Fri Jan 01 01:01:02 2021 | b | 2
Fri Jan 01 01:01:03 2021 | ç | 2
(3 rows)