Dialects

Eight dialects, one grammar.

Every dialect reads the same sgl. directives. Each has its own parser, types and built-in functions, so a query is checked the way your database will run it.

DialectPlaceholdersRETURNINGMigrationsIntrospectionGo drivers
PostgreSQLpostgres$1yesyesyesdatabase/sql, pgx
CockroachDBcockroachdb$1yesyesyesdatabase/sql, pgx
TimescaleDBtimescaledb$1yesyesyesdatabase/sql, pgx
MySQLmysql?opt-inyesnodatabase/sql
MariaDBmariadb?INSERT, DELETEyesnodatabase/sql
SQLitesqlite?1yesyesyesdatabase/sql
DuckDBduckdb$1yesyesnodatabase/sql
ClickHouseclickhouse{name:Type}noyesnodatabase/sql, clickhouse native

Generated code works with the standard library's database/sql for every dialect. The pgx driver adds batches and COPY FROM for the PostgreSQL family, and ClickHouse has a native-protocol driver.

PostgreSQL

postgres family

The reference dialect, with extension hooks for flavours such as TimescaleDB.

In sgl.yaml
dialect: postgres
Placeholders
$1 and named :name
Default schema
public
RETURNING
yes
Migrations
PostgreSQL backend, each in a transaction; lock: advisory lock, or a lock table behind PgBouncer
Live schema
sgl schema dump --from-db and sgl schema diff
Go drivers
database/sql, pgx
sgl connects with
pgx
Golden cases
87

CockroachDB

built on postgres

PostgreSQL's grammar and types, under its own name.

In sgl.yaml
dialect: cockroachdb
Placeholders
$1 and named :name
Default schema
public
RETURNING
yes
Migrations
PostgreSQL backend, each in a transaction; lock: advisory lock
Live schema
sgl schema dump --from-db and sgl schema diff
Go drivers
database/sql, pgx
sgl connects with
pgx
Golden cases
4

TimescaleDB

built on postgres

PostgreSQL plus hypertables, continuous aggregates and Timescale's functions.

In sgl.yaml
dialect: timescaledb
Placeholders
$1 and named :name
Default schema
public
RETURNING
yes
Migrations
PostgreSQL backend, each in a transaction; lock: advisory lock
Live schema
sgl schema dump --from-db and sgl schema diff
Go drivers
database/sql, pgx
sgl connects with
pgx

MySQL

mysql family

Unqualified names resolve in the connection's database; RETURNING is off unless enabled.

In sgl.yaml
dialect: mysql
Placeholders
? and named :name
Default schema
the connection's database
RETURNING
opt-in
Migrations
MySQL backend, each in a transaction; lock: GET_LOCK advisory lock
Live schema
from migrations only
Go drivers
database/sql
sgl connects with
go-sql-driver/mysql
Golden cases
44

MariaDB

built on mysql

MySQL's grammar with MariaDB's RETURNING on INSERT and DELETE.

In sgl.yaml
dialect: mariadb
Placeholders
? and named :name
Default schema
the connection's database
RETURNING
INSERT, DELETE
Migrations
MySQL backend, each in a transaction; lock: GET_LOCK advisory lock
Live schema
from migrations only
Go drivers
database/sql
sgl connects with
go-sql-driver/mysql
Golden cases
4

SQLite

sqlite family

Type affinity is mapped to Go types; the stock driver is pure Go.

In sgl.yaml
dialect: sqlite
Placeholders
?1 and named :name @name $name
Default schema
main
RETURNING
yes
Migrations
SQLite backend, each in a transaction; lock: none needed: one writer
Live schema
sgl schema dump --from-db and sgl schema diff
Go drivers
database/sql
sgl connects with
modernc.org/sqlite
Golden cases
56

DuckDB

duckdb family

DuckDB's driver needs cgo, so the stock sgl generates code only: migrate from your own program or a custom sgl build.

In sgl.yaml
dialect: duckdb
Placeholders
$1 and named :name
Default schema
main
RETURNING
yes
Migrations
DuckDB backend, each in a transaction; lock: none needed: the database file admits one process
Live schema
from migrations only
Go drivers
database/sql
sgl connects with
none in the stock binary: build sgl with the DuckDB driver
Golden cases
57

ClickHouse

clickhouse family

Typed {name:Type} parameters, asyncexec for ALTER UPDATE and DELETE, and a native-protocol emitter.

In sgl.yaml
dialect: clickhouse
Placeholders
{name:Type}
Default schema
default
RETURNING
no
Mutations
asynchronous: use asyncexec
Migrations
ClickHouse backend, without transactions; lock: none: run migrations from one place, such as CI
Live schema
from migrations only
Go drivers
database/sql, clickhouse native
sgl connects with
clickhouse-go
Golden cases
80
Bring your own

Write a dialect.

A dialect is a Go package that implements one interface. Flavours such as CockroachDB and TimescaleDB extend a base dialect with hooks for extra types, functions and statements, and every dialect is held to the same conformance and golden tests.

Read the dialect packages