mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-28 09:46:44 +08:00
PG12 introduced new feature which allows to define auto generated columns. This PR adds check which prevents using such columns for hypertable partitioning.
44 lines
1.1 KiB
Plaintext
44 lines
1.1 KiB
Plaintext
-- This file and its contents are licensed under the Apache License 2.0.
|
|
-- Please see the included NOTICE for copyright information and
|
|
-- LICENSE-APACHE for a copy of the license.
|
|
--
|
|
-- Generated columns support tests
|
|
--
|
|
CREATE TABLE foo (
|
|
a INT NOT NULL,
|
|
b INT,
|
|
c INT GENERATED ALWAYS AS (a + b) STORED
|
|
);
|
|
SELECT table_name FROM create_hypertable('foo', 'a', chunk_time_interval=>10);
|
|
table_name
|
|
------------
|
|
foo
|
|
(1 row)
|
|
|
|
INSERT INTO foo(a, b) VALUES(1, 2);
|
|
INSERT INTO foo(a, b) VALUES(2, 3);
|
|
-- Ensure generated column cannot be updated
|
|
\set ON_ERROR_STOP 0
|
|
INSERT INTO foo VALUES(3, 5, 8);
|
|
ERROR: cannot insert into column "c"
|
|
\set ON_ERROR_STOP 1
|
|
SELECT * FROM foo ORDER BY a;
|
|
a | b | c
|
|
---+---+---
|
|
1 | 2 | 3
|
|
2 | 3 | 5
|
|
(2 rows)
|
|
|
|
DROP TABLE foo;
|
|
-- Ensure that generated column cannot be used for partitioning
|
|
-- Generated as expression
|
|
CREATE TABLE bar (
|
|
a INT NOT NULL,
|
|
b INT GENERATED ALWAYS AS (a + 123) STORED
|
|
);
|
|
\set ON_ERROR_STOP 0
|
|
SELECT table_name FROM create_hypertable('bar', 'a', 'b', 2, chunk_time_interval=>10);
|
|
ERROR: invalid partitioning column
|
|
\set ON_ERROR_STOP 1
|
|
DROP TABLE bar;
|