Hi! Why I can not create Continuous Aggregate if type of column is TIMESTAMP?
CREATE TABLE test.hypertable(
id INTEGER GENERATED ALWAYS AS IDENTITY,
ts TIMESTAMP,
val1 INTEGER,
val2 INTEGER
);
SELECT api_bet.create_hypertable(
relation => 'test.hypertable',
dimension => api_bet.by_range('ts', INTERVAL '30 days')
);
INSERT INTO test.hypertable(ts, val1, val2)
VALUES(TIMESTAMP '2025-01-01', 0, 0),
(TIMESTAMP '2025-02-05', 1, 1),
(TIMESTAMP '2025-03-07', 2, 0),
(TIMESTAMP '2025-03-15', 3, 3)
;
SELECT * FROM test.hypertable;
SELECT
api_bet.time_bucket(bucket_width => INTERVAL '1 day', ts => 'ts'),
COUNT(id) AS rows_count,
COUNT(val1) FILTER(WHERE val1 > 0) AS val1_count,
COUNT(val2) FILTER(WHERE val2 > 0) AS val2_count
FROM test.hypertable
GROUP BY
api_bet.time_bucket(bucket_width => INTERVAL '1 day', ts => 'ts')
;
Output:
SQL Error [22007]: ERROR: invalid input syntax for type timestamp with time zone: "ts"
But the documentation for time_bucket function says that user can use TIMESTAMP for bucket column:
Required arguments for interval time inputs
Name Type Description bucket_width
INTERVAL A Postgres time interval for how long each bucket is ts
DATE, TIMESTAMP, or TIMESTAMPTZ The timestamp to bucket
UPD. The question is erroneous, because the author incorrectly used the second parameter. It should be deleted so as not to mislead people.