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

[Bug]: Failed to add a column in a hypertable #4087

Closed
krvajal opened this issue Feb 11, 2022 · 3 comments · Fixed by #4159
Closed

[Bug]: Failed to add a column in a hypertable #4087

krvajal opened this issue Feb 11, 2022 · 3 comments · Fixed by #4159
Assignees
Labels
bug compression ddl Issues that involve DDL handling low-hanging-fruit Label for issues that are easy to implement multinode

Comments

@krvajal
Copy link

krvajal commented Feb 11, 2022

What type of bug is this?

Unexpected error

What subsystems and features are affected?

Distributed hypertable

What happened?

When trying to add a column to an hypertable

ALTER TABLE table_name ADD COLUMN  IF NOT EXISTS  "medium" VARCHAR ;

and if the column already exists.
I get the following error

Query 1 ERROR: ERROR:  column "medium" of relation "_compressed_hypertable_9" already exists`

TimescaleDB version affected

2.5.0

PostgreSQL version used

14.1

What operating system did you use?

What installation method did you use?

Not applicable

What platform did you run on?

Managed Service for TimescaleDB (MST/Aiven)

Relevant log output and stack trace

Query 1 ERROR: ERROR:  column "medium" of relation "_compressed_hypertable_9" already exists

How can we reproduce the bug?

See the description above
@krvajal krvajal added the bug label Feb 11, 2022
@krvajal krvajal changed the title [Bug]: <Title> [Bug]: Failed to add a column in a hypertable Feb 11, 2022
@mkindahl
Copy link
Contributor

@krvajal This error comes from the compression subsystem. Could you please add the hypertable definition and the call to create_hypertable or create_distributed_hypertable that you used?

@patrickFuerst
Copy link

We have the same problem with compressed hypertables.
Looks like IF NOT EXISTS is ignored and throws an error anyway.

TimescaleDB version affected
2.6.0

Our table looks something like this: (I omitted other columns for simplicity ).

CREATE TABLE IF NOT EXISTS "data"
(
    time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    path TEXT NOT NULL,
    speed REAL NULL
)

SELECT create_hypertable('data', 'time', 'path', 2,  if_not_exists => TRUE);

ALTER TABLE "data" SET (
	timescaledb.compress,
	timescaledb.compress_segmentby = 'path',
	timescaledb.compress_orderby = 'time DESC'
);

@mkindahl
Copy link
Contributor

@patrickFuerst @krvajal Thank you for the bug report, it was straightforward to reproduce.

foo=# \dx
                                       List of installed extensions
    Name     |  Version  |   Schema   |                            Description                            
-------------+-----------+------------+-------------------------------------------------------------------
 plpgsql     | 1.0       | pg_catalog | PL/pgSQL procedural language
 timescaledb | 2.6.0-dev | public     | Enables scalable inserts and complex queries for time-series data
(2 rows)

foo=# CREATE TABLE metric (time TIMESTAMPTZ NOT NULL, val FLOAT8 NOT NULL, dev_id INT4 NOT NULL);
CREATE TABLE
foo=# SELECT create_hypertable('metric', 'time', 'dev_id', 10);
  create_hypertable  
---------------------
 (1,public,metric,t)
(1 row)

foo=# ALTER TABLE metric SET (                                      
timescaledb.compress,
timescaledb.compress_segmentby = 'dev_id',
timescaledb.compress_orderby = 'time DESC'
);
ALTER TABLE
foo=# INSERT INTO metric(time, val, dev_id)
SELECT s.*, 3.14+1, 1
FROM generate_series('2021-08-17 00:00:00'::timestamp,
                     '2021-08-17 00:02:00'::timestamp, '1 s'::interval) s;
INSERT 0 121
foo=# SELECT compress_chunk(show_chunks('metric'));
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk
(1 row)

foo=# ALTER TABLE metric ADD COLUMN IF NOT EXISTS "medium" VARCHAR ;
ALTER TABLE
foo=# ALTER TABLE metric ADD COLUMN IF NOT EXISTS "medium" VARCHAR ;
NOTICE:  column "medium" of relation "metric" already exists, skipping
ERROR:  column "medium" of relation "_compressed_hypertable_2" already exists

@mkindahl mkindahl added ddl Issues that involve DDL handling low-hanging-fruit Label for issues that are easy to implement and removed waiting-for-author labels Feb 25, 2022
@konskov konskov self-assigned this Mar 10, 2022
konskov added a commit to konskov/timescaledb that referenced this issue Mar 11, 2022
When an ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... command is executed
and the column already exists, we get an error message that the column already
exists on the compressed hypertable, even though IF NOT EXISTS is specified.
This PR removes this error.

Fix timescale#4087
konskov added a commit to konskov/timescaledb that referenced this issue Mar 11, 2022
When an ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... command is executed
and the column already exists, we get an error message that the column already
exists on the compressed hypertable, even though IF NOT EXISTS is specified.
This PR removes this error.

Fix timescale#4087
konskov added a commit to konskov/timescaledb that referenced this issue Mar 11, 2022
When an ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... command is executed
and the column already exists, we get an error message that the column already
exists on the compressed hypertable, even though IF NOT EXISTS is specified.
This PR removes this error.

Fix timescale#4087
konskov added a commit to konskov/timescaledb that referenced this issue Mar 14, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix timescale#4087
konskov added a commit to konskov/timescaledb that referenced this issue Mar 14, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix timescale#4087
konskov added a commit to konskov/timescaledb that referenced this issue Mar 31, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix timescale#4087
konskov added a commit to konskov/timescaledb that referenced this issue Mar 31, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix timescale#4087
konskov added a commit to konskov/timescaledb that referenced this issue Mar 31, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix timescale#4087
konskov added a commit to konskov/timescaledb that referenced this issue Mar 31, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix timescale#4087
konskov added a commit to konskov/timescaledb that referenced this issue Apr 1, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix timescale#4087
konskov added a commit that referenced this issue Apr 1, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix #4087
RafiaSabih pushed a commit to RafiaSabih/timescaledb that referenced this issue Apr 5, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix timescale#4087
RafiaSabih pushed a commit to RafiaSabih/timescaledb that referenced this issue Apr 8, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix timescale#4087
mkindahl pushed a commit to RafiaSabih/timescaledb that referenced this issue Apr 8, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix timescale#4087
svenklemm pushed a commit that referenced this issue Apr 11, 2022
Stop throwing exception with message "column of relation already exists"
when running the command ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
on compressed hypertables.

Fix #4087
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug compression ddl Issues that involve DDL handling low-hanging-fruit Label for issues that are easy to implement multinode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants