mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-17 02:53:51 +08:00
Error if add_dimension given both partition number and interval length
This commit is contained in:
parent
382b712b8b
commit
f2d5c3fc5d
@ -95,6 +95,9 @@ BEGIN
|
|||||||
IF num_slices IS NULL AND interval_length IS NULL THEN
|
IF num_slices IS NULL AND interval_length IS NULL THEN
|
||||||
RAISE EXCEPTION 'The number of slices/partitions or an interval must be specified'
|
RAISE EXCEPTION 'The number of slices/partitions or an interval must be specified'
|
||||||
USING ERRCODE = 'IO101';
|
USING ERRCODE = 'IO101';
|
||||||
|
ELSIF num_slices IS NOT NULL AND interval_length IS NOT NULL THEN
|
||||||
|
RAISE EXCEPTION 'Cannot specify both interval and number of slices/partitions for a single dimension'
|
||||||
|
USING ERRCODE = 'IO101';
|
||||||
END IF;
|
END IF;
|
||||||
EXECUTE format('SELECT TRUE FROM %s LIMIT 1', main_table) INTO table_has_items;
|
EXECUTE format('SELECT TRUE FROM %s LIMIT 1', main_table) INTO table_has_items;
|
||||||
|
|
||||||
|
@ -34,10 +34,6 @@
|
|||||||
-- reconfigured, but the new partitioning only affects newly created
|
-- reconfigured, but the new partitioning only affects newly created
|
||||||
-- chunks.
|
-- chunks.
|
||||||
--
|
--
|
||||||
-- NOTE: Due to current restrictions, a maximum of two dimensions are
|
|
||||||
-- allowed, typically one open (time) and one closed (space)
|
|
||||||
-- dimension.
|
|
||||||
--
|
|
||||||
CREATE TABLE IF NOT EXISTS _timescaledb_catalog.hypertable (
|
CREATE TABLE IF NOT EXISTS _timescaledb_catalog.hypertable (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
schema_name NAME NOT NULL CHECK (schema_name != '_timescaledb_catalog'),
|
schema_name NAME NOT NULL CHECK (schema_name != '_timescaledb_catalog'),
|
||||||
|
@ -6,7 +6,7 @@ CREATE DATABASE single;
|
|||||||
\c single
|
\c single
|
||||||
CREATE EXTENSION IF NOT EXISTS timescaledb;
|
CREATE EXTENSION IF NOT EXISTS timescaledb;
|
||||||
create schema test_schema;
|
create schema test_schema;
|
||||||
create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int);
|
create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int);
|
||||||
\dt "test_schema".*
|
\dt "test_schema".*
|
||||||
List of relations
|
List of relations
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
@ -64,11 +64,14 @@ select * from _timescaledb_catalog.dimension;
|
|||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
\set ON_ERROR_STOP 0
|
\set ON_ERROR_STOP 0
|
||||||
--adding the same dimension twice should afail
|
--adding the same dimension twice should fail
|
||||||
select add_dimension('test_schema.test_table', 'location', 2);
|
select add_dimension('test_schema.test_table', 'location', 2);
|
||||||
ERROR: A dimension on column "location" already exists
|
ERROR: A dimension on column "location" already exists
|
||||||
|
--adding dimension with both number_partitions and interval_length should fail
|
||||||
|
select add_dimension('test_schema.test_table', 'id2', number_partitions => 2, interval_length => 1000);
|
||||||
|
ERROR: Cannot specify both interval and number of slices/partitions for a single dimension
|
||||||
--adding a new dimension on a non-empty table should also fail
|
--adding a new dimension on a non-empty table should also fail
|
||||||
insert into test_schema.test_table values (123456789, 23.8, 'blue', 'type1', 'nyc', 1);
|
insert into test_schema.test_table values (123456789, 23.8, 'blue', 'type1', 'nyc', 1, 1);
|
||||||
select add_dimension('test_schema.test_table', 'device_type', 2);
|
select add_dimension('test_schema.test_table', 'device_type', 2);
|
||||||
ERROR: Cannot add new dimension to a non-empty table
|
ERROR: Cannot add new dimension to a non-empty table
|
||||||
\set ON_ERROR_STOP 1
|
\set ON_ERROR_STOP 1
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
\ir include/create_single_db.sql
|
\ir include/create_single_db.sql
|
||||||
|
|
||||||
create schema test_schema;
|
create schema test_schema;
|
||||||
create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int);
|
create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int);
|
||||||
|
|
||||||
\dt "test_schema".*
|
\dt "test_schema".*
|
||||||
select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||||
@ -17,11 +17,14 @@ select * from _timescaledb_catalog.hypertable where table_name = 'test_table';
|
|||||||
select * from _timescaledb_catalog.dimension;
|
select * from _timescaledb_catalog.dimension;
|
||||||
|
|
||||||
\set ON_ERROR_STOP 0
|
\set ON_ERROR_STOP 0
|
||||||
--adding the same dimension twice should afail
|
--adding the same dimension twice should fail
|
||||||
select add_dimension('test_schema.test_table', 'location', 2);
|
select add_dimension('test_schema.test_table', 'location', 2);
|
||||||
|
|
||||||
|
--adding dimension with both number_partitions and interval_length should fail
|
||||||
|
select add_dimension('test_schema.test_table', 'id2', number_partitions => 2, interval_length => 1000);
|
||||||
|
|
||||||
--adding a new dimension on a non-empty table should also fail
|
--adding a new dimension on a non-empty table should also fail
|
||||||
insert into test_schema.test_table values (123456789, 23.8, 'blue', 'type1', 'nyc', 1);
|
insert into test_schema.test_table values (123456789, 23.8, 'blue', 'type1', 'nyc', 1, 1);
|
||||||
select add_dimension('test_schema.test_table', 'device_type', 2);
|
select add_dimension('test_schema.test_table', 'device_type', 2);
|
||||||
\set ON_ERROR_STOP 1
|
\set ON_ERROR_STOP 1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user