Skip to content

Applying filters from WHERE clause with SET #54

Closed

Description

@DanCory

Using the sample data from the documentation, run the following query:

select year, AGGREGATE(revenue) at (set year=year-1) as last, AGGREGATE(revenue) as this from sales_v where region='North' order by year;

This returns:

year, last, this
2023, NULL, 37000
2024, 111000, 59000

The filter region='North' is not being applied in the computation of last.

Is there a way to have the filter apply? I tried various versions of at (visible) and none worked. I could not find a clear statement in the yardstick documentation or the original paper. Of course, I can use a subquery but it seems like there should be a more compact version.

Activity

  1. DanCory commented on Oct 29, 2026

    @DanCory
    Author

    There is an existing yardstick test for

    SELECT year, "AGGREGATE"(current_revenue) AT (VISIBLE SET year = CURRENT year - 1)
    

    However, this test doesn't have a WHERE clause. Adding a WHERE clause in this case does not have it apply.

  2. nicosuave commented on Nov 10, 2026

    @nicosuave
    Member

    Fixed in #69: VISIBLE was being ignored when combined with SET, so use AT (VISIBLE SET year = year - 1) to keep the WHERE filter; plain AT (SET ...) still drops it by design and now warns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions