Skip to content

Add aggregate expressions to Continuous Aggregate#9202

Open
fabriziomello wants to merge 32 commits intotimescale:mainfrom
fabriziomello:cagg_add_column
Open

Add aggregate expressions to Continuous Aggregate#9202
fabriziomello wants to merge 32 commits intotimescale:mainfrom
fabriziomello:cagg_add_column

Conversation

@fabriziomello
Copy link
Member

@fabriziomello fabriziomello commented Jan 28, 2026

Implements add_continuous_aggregate_column() SQL function that allows adding new aggregate expressions to existing Continuous Aggregates without recreating them.

The function updates all internal CAgg structures:

  • Materialization hypertable (adds column for storing computed values)
  • Partial and Direct views (adds aggregate computation)
  • User view (adds column reference or aggregate for real-time mode)

Usage examples:

-- Add aggregate with explicit alias
SELECT add_continuous_aggregate_column('my_cagg', 'sum(value) AS total');

-- Add aggregate without alias (uses function name)
SELECT add_continuous_aggregate_column('my_cagg', 'avg(temperature)');

-- Skip if column already exists
SELECT add_continuous_aggregate_column('my_cagg', 'max(value) AS peak', true);

Limitations:

  • Cannot add aggregates to CAggs with compression enabled
  • Only single aggregate expressions allowed per call
  • Column name must not already exist in the CAgg

@fabriziomello fabriziomello self-assigned this Jan 28, 2026
@fabriziomello fabriziomello force-pushed the cagg_add_column branch 2 times, most recently from c4b999c to 2628be2 Compare January 28, 2026 18:49
@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 86.27451% with 35 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tsl/src/continuous_aggs/alter.c 85.83% 11 Missing and 22 partials ⚠️
tsl/src/continuous_aggs/common.c 89.47% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@fabriziomello fabriziomello force-pushed the cagg_add_column branch 2 times, most recently from 58369ed to cbc4a95 Compare January 29, 2026 19:54
@fabriziomello fabriziomello changed the title Add column to Continuous Aggregate Add aggregate expressions to Continuous Aggregate Feb 3, 2026
@fabriziomello fabriziomello force-pushed the cagg_add_column branch 2 times, most recently from cbbbcad to 68de377 Compare February 3, 2026 15:49
@fabriziomello fabriziomello marked this pull request as ready for review February 4, 2026 00:04
@fabriziomello fabriziomello requested a review from a team February 4, 2026 00:04
@fabriziomello fabriziomello modified the milestone: v2.26.0 Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant