mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 18:13:18 +08:00
The previous default of 30 days was typically too long for most starting use cases, which would lead users to have one large chunk that lacked some of the benefits of using TimescaleDB, at least for the initial chunk. This chunk size should be more reasonable, especially for initial workloads.
539 lines
25 KiB
Plaintext
539 lines
25 KiB
Plaintext
\ir include/insert_single.sql
|
|
CREATE TABLE PUBLIC."one_Partition" (
|
|
"timeCustom" BIGINT NOT NULL,
|
|
device_id TEXT NOT NULL,
|
|
series_0 DOUBLE PRECISION NULL,
|
|
series_1 DOUBLE PRECISION NULL,
|
|
series_2 DOUBLE PRECISION NULL,
|
|
series_bool BOOLEAN NULL
|
|
);
|
|
CREATE INDEX ON PUBLIC."one_Partition" (device_id, "timeCustom" DESC NULLS LAST) WHERE device_id IS NOT NULL;
|
|
CREATE INDEX ON PUBLIC."one_Partition" ("timeCustom" DESC NULLS LAST, series_0) WHERE series_0 IS NOT NULL;
|
|
CREATE INDEX ON PUBLIC."one_Partition" ("timeCustom" DESC NULLS LAST, series_1) WHERE series_1 IS NOT NULL;
|
|
CREATE INDEX ON PUBLIC."one_Partition" ("timeCustom" DESC NULLS LAST, series_2) WHERE series_2 IS NOT NULL;
|
|
CREATE INDEX ON PUBLIC."one_Partition" ("timeCustom" DESC NULLS LAST, series_bool) WHERE series_bool IS NOT NULL;
|
|
\c single :ROLE_SUPERUSER
|
|
CREATE SCHEMA "one_Partition" AUTHORIZATION :ROLE_DEFAULT_PERM_USER;
|
|
\c single :ROLE_DEFAULT_PERM_USER;
|
|
SELECT * FROM create_hypertable('"public"."one_Partition"', 'timeCustom', associated_schema_name=>'one_Partition', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
--output command tags
|
|
\set QUIET off
|
|
BEGIN;
|
|
BEGIN
|
|
\COPY "one_Partition" FROM 'data/ds1_dev1_1.tsv' NULL AS '';
|
|
COPY 7
|
|
COMMIT;
|
|
COMMIT
|
|
INSERT INTO "one_Partition"("timeCustom", device_id, series_0, series_1) VALUES
|
|
(1257987600000000000, 'dev1', 1.5, 1),
|
|
(1257987600000000000, 'dev1', 1.5, 2),
|
|
(1257894000000000000, 'dev2', 1.5, 1),
|
|
(1257894002000000000, 'dev1', 2.5, 3);
|
|
INSERT 0 4
|
|
INSERT INTO "one_Partition"("timeCustom", device_id, series_0, series_1) VALUES
|
|
(1257894000000000000, 'dev2', 1.5, 2);
|
|
INSERT 0 1
|
|
\set QUIET on
|
|
SELECT * FROM test.show_columnsp('"one_Partition".%');
|
|
Relation | Kind | Column | Column type | Nullable
|
|
-----------------------------------------------------------------------------+------+-------------+------------------+----------
|
|
"one_Partition"._hyper_1_1_chunk | r | timeCustom | bigint | t
|
|
"one_Partition"._hyper_1_1_chunk | r | device_id | text | t
|
|
"one_Partition"._hyper_1_1_chunk | r | series_0 | double precision | f
|
|
"one_Partition"._hyper_1_1_chunk | r | series_1 | double precision | f
|
|
"one_Partition"._hyper_1_1_chunk | r | series_2 | double precision | f
|
|
"one_Partition"._hyper_1_1_chunk | r | series_bool | boolean | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_device_id_timeCustom_idx" | i | device_id | text | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_device_id_timeCustom_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_timeCustom_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_timeCustom_series_0_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_timeCustom_series_0_idx" | i | series_0 | double precision | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_timeCustom_series_1_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_timeCustom_series_1_idx" | i | series_1 | double precision | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_timeCustom_series_2_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_timeCustom_series_2_idx" | i | series_2 | double precision | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_timeCustom_series_bool_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_1_chunk_one_Partition_timeCustom_series_bool_idx" | i | series_bool | boolean | f
|
|
"one_Partition"._hyper_1_2_chunk | r | timeCustom | bigint | t
|
|
"one_Partition"._hyper_1_2_chunk | r | device_id | text | t
|
|
"one_Partition"._hyper_1_2_chunk | r | series_0 | double precision | f
|
|
"one_Partition"._hyper_1_2_chunk | r | series_1 | double precision | f
|
|
"one_Partition"._hyper_1_2_chunk | r | series_2 | double precision | f
|
|
"one_Partition"._hyper_1_2_chunk | r | series_bool | boolean | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_device_id_timeCustom_idx" | i | device_id | text | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_device_id_timeCustom_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_timeCustom_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_timeCustom_series_0_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_timeCustom_series_0_idx" | i | series_0 | double precision | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_timeCustom_series_1_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_timeCustom_series_1_idx" | i | series_1 | double precision | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_timeCustom_series_2_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_timeCustom_series_2_idx" | i | series_2 | double precision | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_timeCustom_series_bool_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_2_chunk_one_Partition_timeCustom_series_bool_idx" | i | series_bool | boolean | f
|
|
"one_Partition"._hyper_1_3_chunk | r | timeCustom | bigint | t
|
|
"one_Partition"._hyper_1_3_chunk | r | device_id | text | t
|
|
"one_Partition"._hyper_1_3_chunk | r | series_0 | double precision | f
|
|
"one_Partition"._hyper_1_3_chunk | r | series_1 | double precision | f
|
|
"one_Partition"._hyper_1_3_chunk | r | series_2 | double precision | f
|
|
"one_Partition"._hyper_1_3_chunk | r | series_bool | boolean | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_device_id_timeCustom_idx" | i | device_id | text | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_device_id_timeCustom_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_timeCustom_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_timeCustom_series_0_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_timeCustom_series_0_idx" | i | series_0 | double precision | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_timeCustom_series_1_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_timeCustom_series_1_idx" | i | series_1 | double precision | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_timeCustom_series_2_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_timeCustom_series_2_idx" | i | series_2 | double precision | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_timeCustom_series_bool_idx" | i | timeCustom | bigint | f
|
|
"one_Partition"."_hyper_1_3_chunk_one_Partition_timeCustom_series_bool_idx" | i | series_bool | boolean | f
|
|
(51 rows)
|
|
|
|
SELECT * FROM "one_Partition" ORDER BY "timeCustom", device_id;
|
|
timeCustom | device_id | series_0 | series_1 | series_2 | series_bool
|
|
---------------------+-----------+----------+----------+----------+-------------
|
|
1257894000000000000 | dev1 | 1.5 | 1 | 2 | t
|
|
1257894000000000000 | dev1 | 1.5 | 2 | |
|
|
1257894000000000000 | dev2 | 1.5 | 1 | |
|
|
1257894000000000000 | dev2 | 1.5 | 2 | |
|
|
1257894000000001000 | dev1 | 2.5 | 3 | |
|
|
1257894001000000000 | dev1 | 3.5 | 4 | |
|
|
1257894002000000000 | dev1 | 2.5 | 3 | |
|
|
1257894002000000000 | dev1 | 5.5 | 6 | | t
|
|
1257894002000000000 | dev1 | 5.5 | 7 | | f
|
|
1257897600000000000 | dev1 | 4.5 | 5 | | f
|
|
1257987600000000000 | dev1 | 1.5 | 1 | |
|
|
1257987600000000000 | dev1 | 1.5 | 2 | |
|
|
(12 rows)
|
|
|
|
--test that we can insert data into a 1-dimensional table (only time partitioning)
|
|
CREATE TABLE "1dim"(time timestamp PRIMARY KEY, temp float);
|
|
SELECT create_hypertable('"1dim"', 'time');
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO "1dim" VALUES('2017-01-20T09:00:01', 22.5) RETURNING *;
|
|
time | temp
|
|
--------------------------+------
|
|
Fri Jan 20 09:00:01 2017 | 22.5
|
|
(1 row)
|
|
|
|
INSERT INTO "1dim" VALUES('2017-01-20T09:00:21', 21.2);
|
|
INSERT INTO "1dim" VALUES('2017-01-20T09:00:47', 25.1);
|
|
SELECT * FROM "1dim";
|
|
time | temp
|
|
--------------------------+------
|
|
Fri Jan 20 09:00:01 2017 | 22.5
|
|
Fri Jan 20 09:00:21 2017 | 21.2
|
|
Fri Jan 20 09:00:47 2017 | 25.1
|
|
(3 rows)
|
|
|
|
CREATE TABLE regular_table (time timestamp, temp float);
|
|
INSERT INTO regular_table SELECT * FROM "1dim";
|
|
SELECT * FROM regular_table;
|
|
time | temp
|
|
--------------------------+------
|
|
Fri Jan 20 09:00:01 2017 | 22.5
|
|
Fri Jan 20 09:00:21 2017 | 21.2
|
|
Fri Jan 20 09:00:47 2017 | 25.1
|
|
(3 rows)
|
|
|
|
TRUNCATE TABLE regular_table;
|
|
INSERT INTO regular_table VALUES('2017-01-20T09:00:59', 29.2);
|
|
INSERT INTO "1dim" SELECT * FROM regular_table;
|
|
SELECT * FROM "1dim";
|
|
time | temp
|
|
--------------------------+------
|
|
Fri Jan 20 09:00:01 2017 | 22.5
|
|
Fri Jan 20 09:00:21 2017 | 21.2
|
|
Fri Jan 20 09:00:47 2017 | 25.1
|
|
Fri Jan 20 09:00:59 2017 | 29.2
|
|
(4 rows)
|
|
|
|
SELECT "1dim" FROM "1dim";
|
|
1dim
|
|
-----------------------------------
|
|
("Fri Jan 20 09:00:01 2017",22.5)
|
|
("Fri Jan 20 09:00:21 2017",21.2)
|
|
("Fri Jan 20 09:00:47 2017",25.1)
|
|
("Fri Jan 20 09:00:59 2017",29.2)
|
|
(4 rows)
|
|
|
|
--test that we can insert pre-1970 dates
|
|
CREATE TABLE "1dim_pre1970"(time timestamp PRIMARY KEY, temp float);
|
|
SELECT create_hypertable('"1dim_pre1970"', 'time', chunk_time_interval=> INTERVAL '1 Month');
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO "1dim_pre1970" VALUES('1969-12-01T19:00:00', 21.2);
|
|
INSERT INTO "1dim_pre1970" VALUES('1969-12-20T09:00:00', 25.1);
|
|
INSERT INTO "1dim_pre1970" VALUES('1970-01-20T09:00:00', 26.6);
|
|
INSERT INTO "1dim_pre1970" VALUES('1969-02-20T09:00:00', 29.9);
|
|
--should show warning
|
|
BEGIN;
|
|
CREATE TABLE "1dim_usec_interval"(time timestamp PRIMARY KEY, temp float);
|
|
SELECT create_hypertable('"1dim_usec_interval"', 'time', chunk_time_interval=> 10);
|
|
WARNING: unexpected interval: smaller than one second
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO "1dim_usec_interval" VALUES('1969-12-01T19:00:00', 21.2);
|
|
ROLLBACK;
|
|
CREATE TABLE "1dim_usec_interval"(time timestamp PRIMARY KEY, temp float);
|
|
SELECT create_hypertable('"1dim_usec_interval"', 'time', chunk_time_interval=> 1000000);
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO "1dim_usec_interval" VALUES('1969-12-01T19:00:00', 21.2);
|
|
CREATE TABLE "1dim_neg"(time INTEGER, temp float);
|
|
SELECT create_hypertable('"1dim_neg"', 'time', chunk_time_interval=>10);
|
|
NOTICE: adding not-null constraint to column "time"
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO "1dim_neg" VALUES (-20, 21.2);
|
|
INSERT INTO "1dim_neg" VALUES (-19, 21.2);
|
|
INSERT INTO "1dim_neg" VALUES (-1, 21.2);
|
|
INSERT INTO "1dim_neg" VALUES (0, 21.2);
|
|
INSERT INTO "1dim_neg" VALUES (1, 21.2);
|
|
INSERT INTO "1dim_neg" VALUES (19, 21.2);
|
|
INSERT INTO "1dim_neg" VALUES (20, 21.2);
|
|
SELECT * FROM "1dim_pre1970";
|
|
time | temp
|
|
--------------------------+------
|
|
Mon Dec 01 19:00:00 1969 | 21.2
|
|
Sat Dec 20 09:00:00 1969 | 25.1
|
|
Tue Jan 20 09:00:00 1970 | 26.6
|
|
Thu Feb 20 09:00:00 1969 | 29.9
|
|
(4 rows)
|
|
|
|
SELECT * FROM "1dim_neg";
|
|
time | temp
|
|
------+------
|
|
-20 | 21.2
|
|
-19 | 21.2
|
|
-1 | 21.2
|
|
0 | 21.2
|
|
1 | 21.2
|
|
19 | 21.2
|
|
20 | 21.2
|
|
(7 rows)
|
|
|
|
SELECT * FROM _timescaledb_catalog.chunk;
|
|
id | hypertable_id | schema_name | table_name
|
|
----+---------------+-----------------------+-------------------
|
|
1 | 1 | one_Partition | _hyper_1_1_chunk
|
|
2 | 1 | one_Partition | _hyper_1_2_chunk
|
|
3 | 1 | one_Partition | _hyper_1_3_chunk
|
|
4 | 2 | _timescaledb_internal | _hyper_2_4_chunk
|
|
5 | 3 | _timescaledb_internal | _hyper_3_5_chunk
|
|
6 | 3 | _timescaledb_internal | _hyper_3_6_chunk
|
|
7 | 3 | _timescaledb_internal | _hyper_3_7_chunk
|
|
8 | 3 | _timescaledb_internal | _hyper_3_8_chunk
|
|
10 | 5 | _timescaledb_internal | _hyper_5_10_chunk
|
|
11 | 6 | _timescaledb_internal | _hyper_6_11_chunk
|
|
12 | 6 | _timescaledb_internal | _hyper_6_12_chunk
|
|
13 | 6 | _timescaledb_internal | _hyper_6_13_chunk
|
|
14 | 6 | _timescaledb_internal | _hyper_6_14_chunk
|
|
15 | 6 | _timescaledb_internal | _hyper_6_15_chunk
|
|
(14 rows)
|
|
|
|
SELECT * FROM _timescaledb_catalog.dimension_slice;
|
|
id | dimension_id | range_start | range_end
|
|
----+--------------+---------------------+---------------------
|
|
1 | 1 | 1257892416000000000 | 1257895008000000000
|
|
2 | 1 | 1257897600000000000 | 1257900192000000000
|
|
3 | 1 | 1257985728000000000 | 1257988320000000000
|
|
4 | 2 | 1484784000000000 | 1485388800000000
|
|
5 | 3 | -5184000000000 | -2592000000000
|
|
6 | 3 | -2592000000000 | 0
|
|
7 | 3 | 0 | 2592000000000
|
|
8 | 3 | -28512000000000 | -25920000000000
|
|
10 | 5 | -2610000000000 | -2609999000000
|
|
11 | 6 | -20 | -10
|
|
12 | 6 | -10 | 0
|
|
13 | 6 | 0 | 10
|
|
14 | 6 | 10 | 20
|
|
15 | 6 | 20 | 30
|
|
(14 rows)
|
|
|
|
-- Create a three-dimensional table
|
|
CREATE TABLE "3dim" (time timestamp, temp float, device text, location text);
|
|
SELECT create_hypertable('"3dim"', 'time', 'device', 2);
|
|
NOTICE: adding not-null constraint to column "time"
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT add_dimension('"3dim"', 'location', 2);
|
|
add_dimension
|
|
---------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO "3dim" VALUES('2017-01-20T09:00:01', 22.5, 'blue', 'nyc');
|
|
INSERT INTO "3dim" VALUES('2017-01-20T09:00:21', 21.2, 'brown', 'sthlm');
|
|
INSERT INTO "3dim" VALUES('2017-01-20T09:00:47', 25.1, 'yellow', 'la');
|
|
--show the constraints on the three-dimensional chunk
|
|
SELECT * FROM test.show_constraints('_timescaledb_internal._hyper_7_16_chunk');
|
|
Constraint | Type | Columns | Index | Expr | Deferrable | Deferred | Validated
|
|
---------------+------+------------+-------+----------------------------------------------------------------------------------------------------------------------------------------------+------------+----------+-----------
|
|
constraint_16 | c | {time} | - | (("time" >= 'Thu Jan 19 00:00:00 2017'::timestamp without time zone) AND ("time" < 'Thu Jan 26 00:00:00 2017'::timestamp without time zone)) | f | f | t
|
|
constraint_17 | c | {device} | - | (_timescaledb_internal.get_partition_hash(device) < 1073741823) | f | f | t
|
|
constraint_18 | c | {location} | - | (_timescaledb_internal.get_partition_hash(location) >= 1073741823) | f | f | t
|
|
(3 rows)
|
|
|
|
--queries should work in three dimensions
|
|
SELECT * FROM "3dim";
|
|
time | temp | device | location
|
|
--------------------------+------+--------+----------
|
|
Fri Jan 20 09:00:01 2017 | 22.5 | blue | nyc
|
|
Fri Jan 20 09:00:47 2017 | 25.1 | yellow | la
|
|
Fri Jan 20 09:00:21 2017 | 21.2 | brown | sthlm
|
|
(3 rows)
|
|
|
|
-- test that explain works
|
|
EXPLAIN (COSTS FALSE)
|
|
INSERT INTO "3dim" VALUES('2017-01-21T09:00:01', 32.9, 'green', 'nyc'),
|
|
('2017-01-21T09:00:47', 27.3, 'purple', 'la') RETURNING *;
|
|
QUERY PLAN
|
|
---------------------------------------------
|
|
Custom Scan (HypertableInsert)
|
|
-> Insert on "3dim"
|
|
-> Custom Scan (ChunkDispatch)
|
|
-> Values Scan on "*VALUES*"
|
|
(4 rows)
|
|
|
|
EXPLAIN (COSTS FALSE)
|
|
WITH "3dim_insert" AS (
|
|
INSERT INTO "3dim" VALUES('2017-01-21T09:01:44', 19.3, 'black', 'la') RETURNING time, temp
|
|
), regular_insert AS (
|
|
INSERT INTO regular_table VALUES('2017-01-21T10:00:51', 14.3) RETURNING time, temp
|
|
) INSERT INTO "1dim" (SELECT time, temp FROM "3dim_insert" UNION SELECT time, temp FROM regular_insert);
|
|
QUERY PLAN
|
|
------------------------------------------------------------------------------
|
|
Custom Scan (HypertableInsert)
|
|
-> Insert on "1dim"
|
|
CTE 3dim_insert
|
|
-> Custom Scan (HypertableInsert)
|
|
-> Insert on "3dim"
|
|
-> Custom Scan (ChunkDispatch)
|
|
-> Result
|
|
CTE regular_insert
|
|
-> Insert on regular_table
|
|
-> Result
|
|
-> Custom Scan (ChunkDispatch)
|
|
-> Unique
|
|
-> Sort
|
|
Sort Key: "3dim_insert"."time", "3dim_insert".temp
|
|
-> Append
|
|
-> CTE Scan on "3dim_insert"
|
|
-> CTE Scan on regular_insert
|
|
(17 rows)
|
|
|
|
-- test prepared statement INSERT
|
|
PREPARE "1dim_plan" (timestamp, float) AS
|
|
INSERT INTO "1dim" VALUES($1, $2) ON CONFLICT (time) DO NOTHING;
|
|
EXECUTE "1dim_plan" ('2017-04-17 23:35', 31.4);
|
|
EXECUTE "1dim_plan" ('2017-04-17 23:35', 32.6);
|
|
-- test prepared statement with generic plan (forced when no parameters)
|
|
PREPARE "1dim_plan_generic" AS
|
|
INSERT INTO "1dim" VALUES('2017-05-18 17:24', 18.3);
|
|
EXECUTE "1dim_plan_generic";
|
|
SELECT * FROM "1dim" ORDER BY time;
|
|
time | temp
|
|
--------------------------+------
|
|
Fri Jan 20 09:00:01 2017 | 22.5
|
|
Fri Jan 20 09:00:21 2017 | 21.2
|
|
Fri Jan 20 09:00:47 2017 | 25.1
|
|
Fri Jan 20 09:00:59 2017 | 29.2
|
|
Mon Apr 17 23:35:00 2017 | 31.4
|
|
Thu May 18 17:24:00 2017 | 18.3
|
|
(6 rows)
|
|
|
|
SELECT * FROM "3dim" ORDER BY (time, device);
|
|
time | temp | device | location
|
|
--------------------------+------+--------+----------
|
|
Fri Jan 20 09:00:01 2017 | 22.5 | blue | nyc
|
|
Fri Jan 20 09:00:21 2017 | 21.2 | brown | sthlm
|
|
Fri Jan 20 09:00:47 2017 | 25.1 | yellow | la
|
|
(3 rows)
|
|
|
|
-- Test that large intervals and no interval fail for INTEGER
|
|
\set ON_ERROR_STOP 0
|
|
CREATE TABLE "inttime_err"(time INTEGER PRIMARY KEY, temp float);
|
|
SELECT create_hypertable('"inttime_err"', 'time', chunk_time_interval=>2147483648);
|
|
ERROR: invalid interval: must be between 1 and 2147483647
|
|
SELECT create_hypertable('"inttime_err"', 'time');
|
|
ERROR: integer dimensions require an explicit interval
|
|
\set ON_ERROR_STOP 1
|
|
SELECT create_hypertable('"inttime_err"', 'time', chunk_time_interval=>2147483647);
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
-- Test that large intervals and no interval fail for SMALLINT
|
|
\set ON_ERROR_STOP 0
|
|
CREATE TABLE "smallinttime_err"(time SMALLINT PRIMARY KEY, temp float);
|
|
SELECT create_hypertable('"smallinttime_err"', 'time', chunk_time_interval=>32768);
|
|
ERROR: invalid interval: must be between 1 and 32767
|
|
SELECT create_hypertable('"smallinttime_err"', 'time');
|
|
ERROR: integer dimensions require an explicit interval
|
|
\set ON_ERROR_STOP 1
|
|
SELECT create_hypertable('"smallinttime_err"', 'time', chunk_time_interval=>32767);
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
--make sure date inserts work even when the timezone changes the
|
|
CREATE TABLE hyper_date(time date, temp float);
|
|
SELECT create_hypertable('"hyper_date"', 'time');
|
|
NOTICE: adding not-null constraint to column "time"
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
SET timezone=+1;
|
|
INSERT INTO "hyper_date" VALUES('2011-01-26', 22.5);
|
|
RESET timezone;
|
|
--make sure timestamp inserts work even when the timezone changes the
|
|
SET timezone = 'UTC';
|
|
CREATE TABLE "test_tz"(time timestamp PRIMARY KEY, temp float);
|
|
SELECT create_hypertable('"test_tz"', 'time', chunk_time_interval=> INTERVAL '1 day');
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO "test_tz" VALUES('2017-09-22 10:00:00', 21.2);
|
|
INSERT INTO "test_tz" VALUES('2017-09-21 19:00:00', 21.2);
|
|
SET timezone = 'US/central';
|
|
INSERT INTO "test_tz" VALUES('2017-09-21 19:01:00', 21.2);
|
|
SELECT * FROM test.show_constraints('_timescaledb_internal._hyper_10_20_chunk');
|
|
Constraint | Type | Columns | Index | Expr | Deferrable | Deferred | Validated
|
|
---------------+------+---------+-------+--------------------------------------------------------------------+------------+----------+-----------
|
|
constraint_23 | c | {time} | - | (("time" >= '01-20-2011'::date) AND ("time" < '01-27-2011'::date)) | f | f | t
|
|
(1 row)
|
|
|
|
SELECT * FROM test_tz;
|
|
time | temp
|
|
--------------------------+------
|
|
Fri Sep 22 10:00:00 2017 | 21.2
|
|
Thu Sep 21 19:00:00 2017 | 21.2
|
|
Thu Sep 21 19:01:00 2017 | 21.2
|
|
(3 rows)
|
|
|
|
-- test various memory settings --
|
|
SET timescaledb.max_open_chunks_per_insert = 10;
|
|
SET timescaledb.max_cached_chunks_per_hypertable = 10;
|
|
CREATE TABLE "nondefault_mem_settings"(time timestamp PRIMARY KEY, temp float);
|
|
SELECT create_hypertable('"nondefault_mem_settings"', 'time', chunk_time_interval=> INTERVAL '1 Month');
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO "nondefault_mem_settings" VALUES('2000-12-01T19:00:00', 21.2);
|
|
INSERT INTO "nondefault_mem_settings" VALUES('2001-12-20T09:00:00', 25.1);
|
|
--lowest possible
|
|
SET timescaledb.max_open_chunks_per_insert = 1;
|
|
SET timescaledb.max_cached_chunks_per_hypertable = 1;
|
|
INSERT INTO "nondefault_mem_settings" VALUES
|
|
('2001-01-20T09:00:00', 26.6),
|
|
('2002-02-20T09:00:00', 27.9),
|
|
('2003-02-20T09:00:00', 28.9);
|
|
INSERT INTO "nondefault_mem_settings" VALUES
|
|
('2001-03-20T09:00:00', 30.6),
|
|
('2002-03-20T09:00:00', 31.9),
|
|
('2003-03-20T09:00:00', 32.9);
|
|
--unlimited
|
|
SET timescaledb.max_open_chunks_per_insert = 0;
|
|
SET timescaledb.max_cached_chunks_per_hypertable = 0;
|
|
INSERT INTO "nondefault_mem_settings" VALUES
|
|
('2001-04-20T09:00:00', 33.6),
|
|
('2002-04-20T09:00:00', 34.9),
|
|
('2003-04-20T09:00:00', 35.9);
|
|
SELECT * FROM "nondefault_mem_settings";
|
|
time | temp
|
|
--------------------------+------
|
|
Fri Dec 01 19:00:00 2000 | 21.2
|
|
Thu Dec 20 09:00:00 2001 | 25.1
|
|
Sat Jan 20 09:00:00 2001 | 26.6
|
|
Wed Feb 20 09:00:00 2002 | 27.9
|
|
Thu Feb 20 09:00:00 2003 | 28.9
|
|
Tue Mar 20 09:00:00 2001 | 30.6
|
|
Wed Mar 20 09:00:00 2002 | 31.9
|
|
Thu Mar 20 09:00:00 2003 | 32.9
|
|
Fri Apr 20 09:00:00 2001 | 33.6
|
|
Sat Apr 20 09:00:00 2002 | 34.9
|
|
Sun Apr 20 09:00:00 2003 | 35.9
|
|
(11 rows)
|
|
|
|
--test rollback
|
|
BEGIN;
|
|
\set QUIET off
|
|
CREATE TABLE "data_records" ("time" bigint NOT NULL, "value" integer CHECK (VALUE >= 0));
|
|
CREATE TABLE
|
|
SELECT create_hypertable('data_records', 'time', chunk_time_interval => 2592000000);
|
|
create_hypertable
|
|
-------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO "data_records" ("time", "value") VALUES (0, 1);
|
|
INSERT 0 1
|
|
SAVEPOINT savepoint_1;
|
|
SAVEPOINT
|
|
INSERT INTO "data_records" ("time", "value") VALUES (1, 0);
|
|
INSERT 0 1
|
|
ROLLBACK TO SAVEPOINT savepoint_1;
|
|
ROLLBACK
|
|
INSERT INTO "data_records" ("time", "value") VALUES (2, 1);
|
|
INSERT 0 1
|
|
SAVEPOINT savepoint_2;
|
|
SAVEPOINT
|
|
\set ON_ERROR_STOP 0
|
|
INSERT INTO "data_records" ("time", "value") VALUES (3, -1);
|
|
ERROR: new row for relation "_hyper_13_34_chunk" violates check constraint "data_records_value_check"
|
|
\set ON_ERROR_STOP 1
|
|
ROLLBACK TO SAVEPOINT savepoint_2;
|
|
ROLLBACK
|
|
INSERT INTO "data_records" ("time", "value") VALUES (4, 1);
|
|
INSERT 0 1
|
|
SAVEPOINT savepoint_3;
|
|
SAVEPOINT
|
|
INSERT INTO "data_records" ("time", "value") VALUES (5, 0);
|
|
INSERT 0 1
|
|
ROLLBACK TO SAVEPOINT savepoint_3;
|
|
ROLLBACK
|
|
SELECT * FROM data_records;
|
|
time | value
|
|
------+-------
|
|
0 | 1
|
|
2 | 1
|
|
4 | 1
|
|
(3 rows)
|
|
|
|
\set QUIET on
|
|
ROLLBACK;
|