> Public product help. This page has no customer entries, projects, chat transcripts, API keys, or horizon contents.
> Reading that data requires `Authorization: Bearer` (a signed-in app session JWT, or a Headless access token).
> Do not call Supabase `/rest/v1` with a Headless JWT. Data reads go through `/casc/v1/headless/v1/rest`.

# Views

Zagger Views are saved SQL definitions per horizon. Configure them in **Settings → Views**. They are **not** PostgreSQL `CREATE VIEW` objects.

## What views store

- **Label** — unique display name in the horizon.
- **Table column** — which logical column the view is associated with (documentation / UI hint).
- **SQL syntax** — fragment or SELECT depending on type.
- **View type** — `filter`, `sort`, or `sql` (SQL / compute).
- **Private** — restrict visibility to owner and admins when enabled.

## Filter views

Example:

```
WHERE raw->>'status' = 'active'
```

Used by Transformation **Filter** steps (and future consumers of filter fragments).

## Sort views

Example:

```
ORDER BY raw->>'company_name' ASC
```

## SQL / compute views

Type `sql` stores a SQLite `SELECT` against a virtual table named `rows`
whose columns are the current Transformation pipeline field names. Used by the
**SQL compute (Zagger View)** transform step for fiscal weeks, window functions, and overtime.

```
SELECT
  rows.*,
  date(
    start_time,
    '-' || ((CAST(strftime('%w', start_time) AS INTEGER)
             + 7 - week_start_dow) % 7) || ' days'
  ) AS fiscal_week,
  SUM(hours) OVER (
    PARTITION BY employee_id, fiscal_week
    ORDER BY jd, project_id
    ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
  ) AS hours_before_entry
FROM rows;
```

You may omit `FROM rows`; the runner adds it when missing. Only a single `SELECT` is allowed (no DML/DDL).
See [transform-ingestion](transform-ingestion.md) for composing SQL Views with Filter/Sort Views.

## Creating a view

1. **Settings → Views → Add**.
2. Enter label and table column.
3. Choose filter, sort, or SQL / compute; paste SQL.
4. Use **Validate** if available; save.

## Relationship to Transformations

Transformations select Zagger Views as Filter, Sort, or SQL compute steps
(see [transform-ingestion](transform-ingestion.md)). The transform runner applies the View’s `sql_syntax`
when you preview or materialize.

## Permissions

Any user with horizon access can create views on that horizon. Private views follow the same ownership model as private ingestion groups.
