Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adding column with NULL constraint #5152

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ accidentally triggering the load of a previous DB version.**

**Bugfixes**
* #4926 Fix corruption when inserting into compressed chunks
* #5152 Fix adding column with NULL constraint to compressed hypertable

**Thanks**
* @ikkala for reporting error when adding column with NULL constraint to compressed hypertable

## 2.9.1 (2022-12-23)

Expand Down
8 changes: 8 additions & 0 deletions src/process_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ check_altertable_add_column_for_compressed(Hypertable *ht, ColumnDef *col)
Constraint *constraint = lfirst_node(Constraint, lc);
switch (constraint->contype)
{
/*
* We can safelly ignore NULL constraints because it does nothing
* and according to Postgres docs is useless and exist just for
* compatibility with other database systems
* https://www.postgresql.org/docs/current/ddl-constraints.html#id-1.5.4.6.6
*/
case CONSTR_NULL:
continue;
case CONSTR_NOTNULL:
has_notnull = true;
continue;
Expand Down
5 changes: 4 additions & 1 deletion tsl/test/expected/compression_ddl.out
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ WARNING: column type "timestamp without time zone" used for "time" does not fol
(1 row)

ALTER TABLE records SET (timescaledb.compress = true);
ALTER TABLE records ADD COLUMN col boolean DEFAULT false NOT NULL;
ALTER TABLE records ADD COLUMN col1 boolean DEFAULT false NOT NULL;
-- NULL constraints are useless and it is safe allow adding this
-- column with NULL constraint to a compressed hypertable (Issue #5151)
ALTER TABLE records ADD COLUMN col2 BOOLEAN NULL;
DROP table records CASCADE;
-- TABLESPACES
-- For tablepaces with compressed chunks the semantics are the following:
Expand Down
5 changes: 4 additions & 1 deletion tsl/test/sql/compression_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ ALTER TABLE test1 ALTER COLUMN b SET STATISTICS 10;
CREATE TABLE records (time timestamp NOT NULL);
SELECT create_hypertable('records', 'time');
ALTER TABLE records SET (timescaledb.compress = true);
ALTER TABLE records ADD COLUMN col boolean DEFAULT false NOT NULL;
ALTER TABLE records ADD COLUMN col1 boolean DEFAULT false NOT NULL;
-- NULL constraints are useless and it is safe allow adding this
-- column with NULL constraint to a compressed hypertable (Issue #5151)
ALTER TABLE records ADD COLUMN col2 BOOLEAN NULL;
DROP table records CASCADE;

-- TABLESPACES
Expand Down