Skip to content

effect/sql treats SQL as one language across dialects #10769

Open

Description

@fubhy

Problem

effect/sql treats SQL as one language that every database speaks with minor variations. A SqlClient carries one dialect from a closed list, and code that has to work across databases branches on that list. Each new database stretches this assumption a little further.

Two things share the name "SQL" here, and only one of them is universal:

  • The session: connections and pooling, transactions, streaming, row transforms, errors, tracing, reactivity, and the mechanics of the sql template (fragments, parameters, identifiers, helpers such as sql.insert). These work the same way regardless of database.
  • The language: the SQL text itself. In practice it is written for one dialect. Application code targets one database. The only code that needs to run on several dialects is the set of multi-dialect library modules, mostly in effect itself.

The current design models the language as if it were as universal as the session. Where that assumption shows:

1. Dialects are a closed list in effect

Statement.Dialect is "sqlite" | "pg" | "mysql" | "mssql" | "clickhouse", and a compiler must declare one of them. So:

2. Multi-dialect modules silently run SQL written for another dialect

These modules in effect choose SQL with onDialectOrElse:

  • Persistence, KeyValueStore.layerSql, PersistedQueue;
  • the event journal and event log servers;
  • cluster message and runner storage;
  • Migrator, SqlModel.

For a dialect they don't list, they run the orElse branch, which is SQLite or Postgres flavoured. ClickHouse falls through this way today, and Trino would too. Nothing tells the user which modules support which databases. A module that doesn't support a dialect fails at runtime, against the database, with a syntax error.

3. The compiler checks dialect names

The statement compiler hardcodes behaviour by name:

A dialect that differs in one of these ways has to be added to core, even when its driver supplies its own compiler.

4. SqlClient promises capabilities that not every engine has

withTransaction, nested transactions through savepoints, and RETURNING (which SqlModel relies on) are part of the generic client, but not every engine supports them:

The client's type says these work; the database decides at runtime.

What prompted this

Analytics and lakehouse engines in particular don't fit the current model:

Each needs a change to the closed list, falls through the multi-dialect modules, and lacks some of what SqlClient promises. Adding them one at a time keeps the assumption and makes each addition a breaking change in effect.

Not proposing a fix yet

This issue is about agreeing on the problem. Some questions a fix would have to answer:

  1. Should dialect identity be open, so that a driver package can define a dialect without changing effect?
  2. Should multi-dialect modules state which dialects they support, and fail clearly (or not exist) for the rest, instead of running another dialect's SQL?
  3. Should capabilities that depend on the engine (transactions, savepoints, RETURNING) be visible in the client's type rather than discovered at runtime?
  4. Is "SQL" the right level for one shared abstraction, or should the shared part be the session, with the language handled per dialect?

Related: #10621, #10622, #10632 (Trino), #9453 (earlier type-level break to Statement), #2693 (made @effect/sql dialect-agnostic).

Activity

  1. self-assigned this
    on Nov 19, 2026
  2. changed the title [-]effect/sql: let drivers define their own dialect, and a Spark SQL driver[/-] [+]effect/sql treats SQL as one language across dialects[/+] on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions