You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Chunks must have the same columns with their hypertables. create_chunk()
should not allow to have a chunk with additional columns which do not
exist in the parent hypertable. Check columns by name in create_chunk()
when creating a chunk from an existing table.
This commit also forces chunks and hypertable to have the same
expressions for generated columns, even though PostgreSQL inheritance
may allow it.
For PG15, it is allowed to have generated column in chunks if and only
if the corresponding hypertable column is also generated. For later
versions, this is handled by PostgreSQL code.
Copy file name to clipboardExpand all lines: tsl/test/expected/chunk_api.out
+137Lines changed: 137 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -172,4 +172,141 @@ SELECT * FROM test.show_constraints(format('%I.%I', :'CHUNK_SCHEMA', :'CHUNK_NAM
172
172
constraint_6 | c | {time} | - | (("time" >= 'Wed Dec 27 16:00:00 2017 PST'::timestamp with time zone) AND ("time" < 'Wed Jan 03 16:00:00 2018 PST'::timestamp with time zone)) | f | f | t
173
173
(4 rows)
174
174
175
+
TRUNCATE chunkapi;
176
+
-- Create a table with extra columns
177
+
CREATE TABLE extra_col_chunk (time timestamptz NOT NULL, device int, temp float, extra int, CONSTRAINT chunkapi_temp_check CHECK (temp > 0));
178
+
-- Adding a new chunk with extra column should fail
179
+
\set ON_ERROR_STOP 0
180
+
SELECT * FROM _timescaledb_functions.create_chunk('chunkapi', '{"time": [1514419200000000, 1515024000000000]}', NULL, NULL, 'extra_col_chunk');
181
+
ERROR: table "extra_col_chunk" contains column "extra" not found in parent "chunkapi"
182
+
DETAIL: The new chunk can contain only the columns present in parent.
183
+
\set ON_ERROR_STOP 1
184
+
-- It should succeed after dropping the extra column
185
+
ALTER TABLE extra_col_chunk DROP COLUMN extra;
186
+
SELECT * FROM _timescaledb_functions.create_chunk('chunkapi', '{"time": [1514419200000000, 1515024000000000]}', NULL, NULL, 'extra_col_chunk');
0 commit comments