Athena
Fetch

Fetch data

Fetches rows from a table or view using structured conditions, optional pagination, sort instructions, and optional post-processing (`group_by`, `time_granularity`, aggregation options). Notes: - Route selection supports `X-Athena-Client` or direct PostgreSQL URI headers (`x-pg-uri` preferred). - Direct URI auth bypass is allowed when URI credentials include both username and password. - Direct URI requests always execute inline (deferred gateway queue is skipped). - Optional `schema_name` targets a non-default schema. When provided, `table_name` must not already be schema-qualified. - PostgreSQL-backed fetch execution accepts canonical nested `select` payloads and compatibility `select` strings. - Schema-qualified base tables such as `public.chat_subscriptions` are supported. - Relation-side schema qualification such as `users:athena.users(id,username,image)` is supported. - Legacy `columns` + `conditions` payloads remain supported and are still the right shape for wildcard/simple fetches and non-PostgreSQL gateway fetch backends. - Structured fetch auth checks apply to every referenced table in the nested tree when API-key enforcement is enabled. - Relation joins resolve from foreign-key metadata first; ambiguous edges should provide `foreign_key`. - Unsupported in this release: top-level AST request bodies (`operation` / `from` / `fields`), relation `on` shapes, and schema-qualified relation selectors combined with `via`. - `X-Strip-Nulls` can be used to remove null-valued fields from response payloads. - Cache behavior may include `X-Athena-Cached`, `X-Athena-Cache-Outcome`, and `X-Athena-Cache-Source` headers.

POST
/gateway/fetch

Header Parameters

X-User-Id?string
X-Athena-Client?string

Registered Athena client name. Optional when direct PostgreSQL URI headers are provided.

x-pg-uri?string

Preferred direct PostgreSQL URI (postgres://... or jdbc:postgresql://...).

x-athena-jdbc-url?string

Compatibility direct PostgreSQL URI header.

x-jdbc-url?string

Compatibility direct PostgreSQL URI header.

X-Strip-Nulls?string
apikey?string
x-api-key?string

optional API key mirror of the apikey header

x-supabase-url?string

Required when X-Athena-Client is custom_supabase

Formaturi
x-supabase-key?string

Required when X-Athena-Client is custom_supabase

Request Body

application/json

view_name?string
table_name?string

Root table name for legacy and structured fetch bodies.

schema_name?string

Optional schema override (defaults to public search_path behavior).

select?|

Structured select projection. Use nested objects for the canonical Athena contract or a PostgREST/Supabase-style string for compatibility.

where?

Structured filters using eq, neq, gt, lt, or in operators.

where_filters?array<>

Explicit structured filter array used by compatibility rewrites and advanced callers.

orderBy?|array<>

Structured ordering for canonical nested select payloads.

columns?array<>|

Legacy projection contract. Keep using this for wildcard or non-PostgreSQL fetch bodies.

conditions?array<>
limit?integer
current_page?integer
page_size?integer
offset?integer
total_pages?integer
strip_nulls?boolean
group_by?string

Column name to group results by

time_granularity?string

Time granularity for grouping timestamp data

Value in"day" | "hour" | "minute"
aggregation_column?string

Column to aggregate (required when using aggregation_strategy)

aggregation_strategy?string

Aggregation strategy to apply (requires aggregation_column)

Value in"cumulative_sum"
aggregation_dedup?boolean

Whether to deduplicate during aggregation

sortBy?

Optional sort (camelCase). Use sort_by for snake_case.

sort_by?

Optional sort (snake_case). Same shape as sortBy.

Response Body

application/json

application/json

curl -X POST "https://athena-cluster.com/gateway/fetch" \  -H "Content-Type: application/json" \  -d '{    "table_name": "public.chat_subscriptions",    "select": "users:athena.users(id,username,image),user_id",    "where_filters": [      {        "column": "user_id",        "operator": "eq",        "value": "ef7a4c74-cc35-4d32-945a-a5271279ecdb",        "column_cast": "text"      }    ],    "orderBy": [      {        "column": "user_id",        "direction": "desc"      }    ],    "limit": 1  }'
{
  "status": "success",
  "message": "Fetched 1 rows",
  "data": [
    {
      "user_id": "ef7a4c74-cc35-4d32-945a-a5271279ecdb",
      "users": {
        "id": "ef7a4c74-cc35-4d32-945a-a5271279ecdb",
        "username": "floris",
        "image": "https://cdn.example.com/avatar.png"
      }
    }
  ],
  "cache_key": "chat_subscriptions:compatibility:true:7c9b53f4f1f0b902"
}
{
  "status": "error",
  "message": "Invalid structured select request",
  "error": "table 'athena.user' was not found for structured gateway fetch",
  "code": "VALIDATION_FAILED",
  "data": {
    "operation": "fetch"
  }
}
Empty