> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL dialect catalogs

> What each warehouse dialect module admits: its capabilities, function classes and settings profile.

Bijection has no SQL dialect of its own. Typed relations from
[`@bijectionhq/library-relations`](https://docs.bijection.com/sql/relations) are lowered into each
warehouse's own dialect, and native text is written in that dialect. One
dialect module per warehouse protocol decides what is admitted. `bijection
check` and the provider gateway run the same module at the compiler revision
the lock records (`semantics@13.9` today), so a statement passes at the
gateway exactly when it passed at check.

Each module carries three things: a capability catalog, a function table and
a fixed settings profile. A change to any of them is a new compiler revision,
and the lock prints it.

## Capabilities

| Protocol | Cut (travel) | Forwards | Null-preserving left join | `LEAD` | Checked 64-bit arithmetic | Predicates as values | Exact column kinds |
| - | - | - | - | - | - | - | - |
| `sqlSnowflake` | yes | no | yes | yes | no | yes | string, boolean, int64, float64, decimal, instant |
| `sqlBigquery` | yes, at most 7 days | no | yes | yes | yes | yes | same |
| `sqlDatabricks` | yes | no | yes | yes | yes | yes | same |
| `sqlTrino` | yes | yes | yes | yes | yes | yes | same |
| `sqlClickhouse` | no | no | yes, through the profile | no | no | yes | same |
| `sqlRedshift` | no | no | yes | yes | yes | yes | same |
| `sqlServer` | yes | no | yes | yes | yes | no | same |
| `sqlPostgres` | no | no | yes | yes | yes | yes | same, plus duration |
| `sqlMysql` | no | no | yes | yes | yes | yes | same |
| `sqlOracleNet` | yes | no | yes | yes | no | no | same |
| `sqlMotherduck` | no | no | yes | yes | yes | yes | same |
| `sqlHana` | yes | no | yes | yes | yes | no | same |
| `sqlDb2` | yes | no | yes | yes | yes | no | same |
| `sqlVertica` | no | no | yes | yes | no | yes | same |
| `sqlExasol` | no | no | yes | yes | no | yes | same |
| `sqlNetezza` | yes | no | yes | yes | no | yes | string, boolean, int64, decimal, instant |
| `sqlAse` | no | no | yes | no | yes | no | string, boolean, int64, float64, decimal |

* **Cut.** A relation's `travel` needs a cut. Without one, a dated read
  refuses `TravelMissing`. A cut with an engine bound, such as BigQuery's
  seven days, also limits the derived window.
* **Forwards.** Only Trino forwards a federated statement through its
  catalogs.
* **Left join.** A left join, or a fused chain of key routes, needs a miss to
  read null rather than column defaults. ClickHouse gets this from its
  profile.
* **Arithmetic and values.** A typed relation's integer arithmetic needs an
  engine that fails on overflow, as the relation's own semantics do. Without
  it, the arithmetic refuses at check. On an engine without boolean
  values, a predicate cannot be a field or a key.
* **Column kinds.** A field whose kind the wire cannot carry exactly refuses
  at check.

## Join across Trino catalogs

Declare the upstream warehouses and their source relations first. In the
following example, `items` and `tickets` come from Snowflake and Databricks.
Each relation declares its own deletion signal.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, secret, t } from "@bijectionhq/bijection";
import { virtualTable, warehouse } from "@bijectionhq/app-sql";

const snowflake = warehouse({
  protocol: "sqlSnowflake",
  endpoint: "https://acme.snowflakecomputing.com",
  credential: secret(),
  label: label.public,
  requests: { retain: { days: 1 }, message: "Configured request-log retention for this receiver." },
  isolation: "none",
});
const databricks = warehouse({
  protocol: "sqlDatabricks",
  endpoint: "https://acme.cloud.databricks.com",
  credential: secret(),
  label: label.public,
  requests: { retain: { days: 1 }, message: "Configured request-log retention for this receiver." },
  isolation: "none",
});
const items = snowflake.relation("SALES.PUBLIC.ITEMS", {
  key: ["item"],
  fields: { item: t.string },
  deletions: snowflake.deletions("SALES.PUBLIC.REMOVED_ITEMS", {
    key: "ITEM", every: { minutes: 1 },
    ordered: {
      position: "EVENT_POS", generation: "LOG_GEN",
      bounds: { relation: "SALES.PUBLIC.REMOVED_ITEMS_BOUNDS", generation: "LOG_GEN", oldest: "OLDEST", head: "HEAD", through: "THROUGH" },
    },
  }),
});
const tickets = databricks.relation("support_datasets.desk.tickets", {
  key: ["item"],
  fields: { item: t.string, status: t.string },
  deletions: databricks.deletions("support_datasets.desk.removed_tickets", {
    key: "item", every: { minutes: 1 },
    ordered: {
      position: "event_pos", generation: "log_gen",
      bounds: { relation: "support_datasets.desk.removed_tickets_bounds", generation: "log_gen", oldest: "oldest", head: "head", through: "through" },
    },
  }),
});

const trino = warehouse({
  protocol: "sqlTrino",
  endpoint: "https://trino.example.com",
  credential: secret(),
  label: label.public,
  requests: { retain: { days: 1 }, message: "Configured request-log retention for this receiver." },
  isolation: "none",
  forwards: {
    sales: { receiver: snowflake, database: "SALES" },
    support: { receiver: databricks, database: "support_datasets" },
  },
});

const itemTickets = virtualTable(trino.sql({
  key: ["item"],
  fields: { item: t.string, status: t.maybe(t.string) },
})`
  SELECT i.item, t.status
  FROM ${items} i LEFT JOIN ${tickets} t ON t.item = i.item
`, {
  label: label.public,
  pushdown: { first: 20, keys: 4 },
  fresh: { seconds: 30 },
  evict: { hours: 1 },
});
```

Trino runs the join. The nullable field covers an item with no ticket, and
the declared key must identify at most one row per item. Bijection polls
each deletion signal on that input's own receiver. A deletion on either
input closes the joined table's landed answers. For a relation without a
deletion signal, declare a `lifetime` on the virtual table.

## Function classes

Native text may call a function only when the dialect's table classifies
it. Typed relations admit only the deterministic classes.

| Class | Native text | Typed relation |
| - | - | - |
| Scalar, aggregate, window | admitted | admitted; a dialect-specific built-in pins the relation to that dialect |
| Row-local table function (`FLATTEN`, `UNNEST`), relation-free table function (`GENERATE_SERIES`) | admitted | admitted |
| Relation-reading table function | refused, `FunctionRefused` | refused |
| Nondeterministic | refused, `FunctionRefused` | refused |
| Credential or session context | refused, `FunctionRefused` | refused |
| Clock | refused, `FunctionRefused`: splice `${at}` | refused: use `at` |
| External | refused, `FunctionRefused` | refused |
| Not in the table, or a qualified name | refused, `FunctionUnclassified` | refused |

Every dialect shares this table:

| Class | Functions |
| - | - |
| Scalar | `ABS`, `CEIL`, `CEILING`, `FLOOR`, `ROUND`, `SIGN`, `MOD`, `POWER`, `SQRT`, `EXP`, `LN`, `GREATEST`, `LEAST`, `COALESCE`, `NULLIF`, `LOWER`, `UPPER`, `TRIM`, `LTRIM`, `RTRIM`, `LENGTH`, `SUBSTRING`, `SUBSTR`, `REPLACE`, `CONCAT`, `LPAD`, `RPAD`, `REVERSE` |
| Aggregate | `COUNT`, `SUM`, `MIN`, `MAX`, `AVG`, `STDDEV_SAMP`, `STDDEV_POP`, `VAR_SAMP`, `VAR_POP` |
| Window | `ROW_NUMBER`, `RANK`, `DENSE_RANK`, `PERCENT_RANK`, `CUME_DIST`, `NTILE`, `LAG`, `LEAD`, `FIRST_VALUE`, `LAST_VALUE`, `NTH_VALUE` |
| Nondeterministic | `RANDOM`, `RAND`, `UUID`, `ANY_VALUE`, `ARBITRARY` |
| Credential context | `CURRENT_USER`, `CURRENT_ROLE`, `SESSION_USER`, `SYSTEM_USER`, `USER`, `CURRENT_SCHEMA`, `CURRENT_DATABASE`, `CURRENT_CATALOG` |
| Clock | `CURRENT_TIMESTAMP`, `CURRENT_DATE`, `CURRENT_TIME`, `LOCALTIMESTAMP`, `LOCALTIME`, `NOW` |

Each dialect adds its own entries, which take precedence:

| Protocol | Admitted additions | Refused additions |
| - | - | - |
| `sqlSnowflake` | scalar `IFF`, `DATEADD`, `NVL`, `NVL2`, `ZEROIFNULL`, `DIV0`; aggregate `COUNT_IF`; row-local `FLATTEN`, `SPLIT_TO_TABLE`; relation-free `GENERATOR` | relation-reading `RESULT_SCAN`, `INFER_SCHEMA`; nondeterministic `UUID_STRING`, `RANDSTR`, `SEQ1`, `SEQ2`, `SEQ4`, `SEQ8`; context `CURRENT_ACCOUNT`, `CURRENT_WAREHOUSE`, `CURRENT_SESSION`, `CURRENT_REGION`, `CURRENT_SECONDARY_ROLES`, `IS_ROLE_IN_SESSION`, `GETVARIABLE`; clock `SYSDATE`, `GETDATE` |
| `sqlBigquery` | scalar `STRPOS`, `TIMESTAMP_ADD`, `CHAR_LENGTH`, `IF`, `IFNULL`, `SAFE_DIVIDE`; aggregate `COUNTIF`, `LOGICAL_AND`, `LOGICAL_OR` | relation-reading `EXTERNAL_QUERY`, `APPENDS`, `CHANGES`, `VECTOR_SEARCH`; nondeterministic `GENERATE_UUID`; clock `CURRENT_DATETIME` |
| `sqlDatabricks` | scalar `INSTR`, `TIMESTAMPADD`, `IF`, `IFNULL`, `NVL`; aggregate `COUNT_IF`; row-local `EXPLODE`, `POSEXPLODE`; relation-free `RANGE` | relation-reading `READ_FILES`, `READ_KAFKA`, `READ_STATE_METADATA`; nondeterministic `RANDN`, `SHUFFLE`; context `CURRENT_METASTORE`, `IS_ACCOUNT_GROUP_MEMBER`, `IS_MEMBER`, `SECRET`; external `AI_QUERY`, `HTTP_REQUEST` |
| `sqlTrino` | scalar `STRPOS`, `IF`, `SEQUENCE`; aggregate `COUNT_IF`, `BOOL_AND`, `BOOL_OR` | context `CURRENT_TIMEZONE` |
| `sqlClickhouse` | scalar `IF`, `IFNULL`, `CHAR_LENGTH`; aggregate `COUNTIF`, `SUMIF`; window `LEADINFRAME`, `LAGINFRAME`; row-local `ARRAYJOIN`; relation-free `NUMBERS`, `ZEROS` | relation-reading `S3`, `URL`, `FILE`, `REMOTE`, `REMOTESECURE`, `CLUSTER`, `POSTGRESQL`, `MYSQL`, `JDBC`, `ICEBERG`, `HDFS`, `MERGE`; nondeterministic `ANY`, `RAND64`, `GENERATEUUIDV4`; clock `NOW64`, `TODAY`; context `CURRENTUSER`, `CURRENTDATABASE` |
| `sqlRedshift` | scalar `STRPOS`, `CHAR_LENGTH`, `NVL`, `NVL2` | clock `GETDATE`, `SYSDATE`; context `CURRENT_USER_ID` |
| `sqlServer` | scalar `CHARINDEX`, `ISNULL`, `IIF`, `LEN`; row-local `OPENJSON` | relation-reading `OPENROWSET`, `OPENQUERY`, `OPENDATASOURCE`, `OPENXML`; nondeterministic `NEWID`, `NEWSEQUENTIALID`; clock `GETDATE`, `GETUTCDATE`, `SYSDATETIME`, `SYSUTCDATETIME`, `SYSDATETIMEOFFSET`; context `SUSER_SNAME`, `SUSER_NAME`, `USER_NAME`, `ORIGINAL_LOGIN`, `SESSION_CONTEXT`, `DB_NAME`, `IS_MEMBER`, `IS_ROLEMEMBER` |
| `sqlPostgres` | scalar `STRPOS`, `CHAR_LENGTH`; aggregate `BOOL_AND`, `BOOL_OR`; row-local `UNNEST`, `JSON_ARRAY_ELEMENTS`, `JSONB_ARRAY_ELEMENTS`; relation-free `GENERATE_SERIES` | relation-reading `DBLINK`, `PG_READ_FILE`, `PG_LS_DIR`; nondeterministic `GEN_RANDOM_UUID`, `SETSEED`; clock `CLOCK_TIMESTAMP`, `STATEMENT_TIMESTAMP`, `TRANSACTION_TIMESTAMP`, `TIMEOFDAY`; context `CURRENT_SETTING`, `PG_BACKEND_PID`, `INET_CLIENT_ADDR` |
| `sqlMysql` | scalar `INSTR`, `CHAR_LENGTH`, `IF`, `IFNULL` | relation-reading `LOAD_FILE`; nondeterministic `UUID_SHORT`; clock `SYSDATE`, `UTC_TIMESTAMP`, `UTC_DATE`, `CURDATE`, `CURTIME`, `UNIX_TIMESTAMP`; context `CONNECTION_ID`, `DATABASE`, `SCHEMA`, `LAST_INSERT_ID`, `FOUND_ROWS` |
| `sqlOracleNet` | scalar `INSTR`, `NVL`, `NVL2`, `DECODE` | nondeterministic `SYS_GUID`; clock `SYSDATE`, `SYSTIMESTAMP`; context `SYS_CONTEXT`, `USERENV`, `UID` |
| `sqlMotherduck` | scalar `STRPOS`, `CHAR_LENGTH`, `IF`, `IFNULL`; aggregate `BOOL_AND`, `BOOL_OR`; row-local `UNNEST`; relation-free `RANGE`, `GENERATE_SERIES` | relation-reading `READ_PARQUET`, `PARQUET_SCAN`, `READ_CSV`, `READ_CSV_AUTO`, `READ_JSON`, `READ_JSON_AUTO`, `GLOB`; nondeterministic `GEN_RANDOM_UUID`; clock `GET_CURRENT_TIMESTAMP`, `TODAY`; context `CURRENT_SETTING` |
| `sqlHana` | scalar `LOCATE`, `IFNULL`, `MAP` | nondeterministic `SYSUUID`, `NEWUID`; clock `CURRENT_UTCTIMESTAMP`, `CURRENT_UTCDATE`, `CURRENT_UTCTIME`; context `SESSION_CONTEXT`, `CURRENT_CONNECTION`, `CURRENT_USER_ID` |
| `sqlDb2` | scalar `LOCATE`, `POSSTR`, `VALUE`, `NVL`, `CHARACTER_LENGTH` | nondeterministic `GENERATE_UNIQUE`, `RAND` |
| `sqlVertica` | scalar `STRPOS`, `CHAR_LENGTH`, `NVL`, `NVL2` | nondeterministic `UUID_GENERATE`; clock `GETDATE`, `GETUTCDATE`, `SYSDATE`, `STATEMENT_TIMESTAMP`, `TRANSACTION_TIMESTAMP`, `CLOCK_TIMESTAMP`; context `CURRENT_SESSION`, `LOCAL_NODE_NAME` |
| `sqlExasol` | scalar `INSTR`, `NVL`, `NVL2`, `DECODE`, `CHARACTER_LENGTH` | nondeterministic `SYS_GUID`; clock `SYSDATE`, `SYSTIMESTAMP`; context `CURRENT_SESSION`, `CURRENT_STATEMENT`, `SESSIONTIMEZONE`, `DBTIMEZONE` |
| `sqlNetezza` | scalar `STRPOS`, `NVL`, `NVL2`, `DECODE`, `ISNULL`, `CHARACTER_LENGTH` | clock `TIMEOFDAY`; context `CURRENT_SID`, `CURRENT_USERID`, `CURRENT_DB` |
| `sqlAse` | scalar `CHARINDEX`, `ISNULL`, `CHAR_LENGTH`, `LEN`, `DATALENGTH` | nondeterministic `NEWID`; clock `GETDATE`, `GETUTCDATE`, `CURRENT_BIGDATETIME`, `CURRENT_BIGTIME`; context `SUSER_NAME`, `SUSER_ID`, `USER_NAME`, `USER_ID`, `DB_NAME`, `DB_ID` |

A typed relation's aggregates are `count`, `sum`, `minimum`, `maximum` and a
distinct `count`, lowered to the shared aggregates.

## Row bounds and population totals

The module also spells the bounded statements Bijection renders. A row bound
is `LIMIT n` by default, `TOP n` on SAP ASE, `TOP (n)` on SQL Server and
`FETCH FIRST n ROWS ONLY` on Oracle and Db2. A population statement groups
by distinct subject and computes the aggregate over that cut before
limiting the returned witnesses. It returns up to its reviewed subject
cap, with each row carrying the same aggregate and distinct-subject count.
The compiler requires window support and exact subject equality. It
supports int64 subjects and text subjects on PostgreSQL and ClickHouse.
Member population statements also require exact source member equality.
[Population total limits](https://docs.bijection.com/sql/application-api.md#read-several-measures-from-one-query)

## Settings profiles

A profile is a fixed set of request settings sent with every statement of the
dialect, typed and native alike. A statement cannot carry `SETTINGS`.

| Protocol | Profile |
| - | - |
| `sqlClickhouse` | `join_use_nulls=1` makes a left join's missing row read null. `count_distinct_implementation=uniqExact` makes population floors count exact distinct subjects. |
| every other protocol | empty |

ClickHouse merged reads are not a profile setting. A relation declares them,
and its references render through `FINAL` in the committed statement (see
[merged reads](https://docs.bijection.com/sql/application-api.md#clickhouse-merged-reads)).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.