Skip to content

[Bug]: Attribute number 7 exceeds number of columns 4 #4894

@MKrkkl

Description

@MKrkkl

What type of bug is this?

Unexpected error

What subsystems and features are affected?

Gapfill

What happened?

I have pg 14 ts 2.8 latest ha image running on docker. docker pull timescale/timescaledb-ha:pg14-ts2.8-latest

Please check below for details to generate test data set.

Using bucket_gapfill and case condition in the same query gives

Attribute number 7 exceeds number of columns 4 error

SELECT time_bucket_gapfill('1 hour', time) as time, CASE WHEN agg in (0,3) THEN max(value) ELSE null END as max, CASE WHEN agg in (0,2) THEN min(value) ELSE null END as min FROM hourly WHERE agg in (0,2,3) and signal in (2) AND level_a = 1 AND level_b = -1 AND time >= '2022-10-01T00:00:00Z' AND time < '2022-10-01T05:59:59Z' GROUP BY 1, agg order by 1;

But if I change last line to GROUP BY 1, agg, level_a, level_b, level_c order by 1; it will work. Why it needs those levels to be part of group by to get it working?

this works as well:

SELECT time_bucket_gapfill('1 hour', time) as time, max(value), min(value), agg FROM hourly WHERE agg in (0,2,3) and signal in (2) AND level_a = 1 AND level_b = -1 AND time >= '2022-10-01T00:00:00Z' AND time < '2022-10-01T05:59:59Z' GROUP BY 1, agg order by 1;

and this

SELECT time_bucket('1 hour', time) as time, CASE WHEN agg in (0,3) THEN max(value) ELSE null END as max, CASE WHEN agg in (0,2) THEN min(value) ELSE null END as min FROM hourly WHERE agg in (0,2,3) and signal in (2) AND level_a = 1 AND level_b = -1 AND time >= '2022-10-01T00:00:00Z' AND time < '2022-10-01T05:59:59Z' GROUP BY 1, agg order by 1;

TimescaleDB version affected

2.8 latest

PostgreSQL version used

14 (latest?)

What operating system did you use?

Ubuntu 20.04.4 LTS x64

What installation method did you use?

Docker

What platform did you run on?

On prem/Self-hosted

Relevant log output and stack trace

No response

How can we reproduce the bug?

CREATE TABLE hourly (
    time timestamptz NOT NULL,
    signal smallint NOT NULL,
    value real,
    level_a integer,
    level_b smallint,
    level_c smallint,
    agg smallint
);

SELECT create_hypertable('hourly', 'time');

INSERT into hourly(time, signal,value, level_a, level_b, level_c, agg) values 
('2022-10-01T00:00:00Z', 2, 685, 1, -1, -1, 2 ),
('2022-10-01T00:00:00Z', 2, 686, 1, -1, -1, 3 ),
('2022-10-01T02:00:00Z', 2, 686, 1, -1, -1, 2 ),
('2022-10-01T02:00:00Z', 2, 687, 1, -1, -1, 3 ),
('2022-10-01T03:00:00Z', 2, 687, 1, -1, -1, 2 ),
('2022-10-01T03:00:00Z', 2, 688, 1, -1, -1, 3 );

SELECT
 time_bucket_gapfill('1 hour', time) as time,
 CASE WHEN agg in (0,3) THEN max(value) ELSE null END as max,
 CASE WHEN agg in (0,2) THEN min(value) ELSE null END as min
 FROM hourly WHERE agg in (0,2,3) and signal in (2) AND level_a = 1 AND level_b = -1 AND time >= '2022-10-01T00:00:00Z' AND time < '2022-10-01T05:59:59Z' 
 GROUP BY 1,  agg order by 1;

Metadata

Metadata

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions