Feature flags
The feature.Feature bitset — every flag the library defines, grouped by category, and the exact sets SQLite and PostgreSQL declare.
Dialect capabilities are bit flags, not name strings. The feature
package defines one bit per optional SQL capability; each dialect declares
support by combining flags with bitwise OR, and query builders branch on
capability:
// Package feature defines bit flags representing optional SQL dialect
// capabilities. Each dialect declares which features it supports by
// combining flags with the bitwise OR operator; query builders branch on
// capability instead of sniffing dialect names.This is why "does this dialect support RETURNING?" is never an
if d.Name() == "postgres" somewhere in the builders — it is a single
Features().Has(feature.Returning) check, and a third-party dialect gets
the same treatment as the in-tree ones.
Working with the bitset
// Has reports whether all bits of flag are present in f.
func (f Feature) Has(flag Feature) bool {
return f&flag == flag
}
// Set returns f with flag added.
func (f Feature) Set(flag Feature) Feature {
return f | flag
}
// Remove returns f with flag cleared.
func (f Feature) Remove(flag Feature) Feature {
return f &^ flag
}String() renders a set in declaration order — "CTE|Returning" — which
makes capability sets readable in logs and String()-interpolated errors.
All flags, by category
Every flag defined in the package, with its one-line meaning:
| Category | Flag | Meaning |
|---|---|---|
| Common | CTE | Common Table Expressions (WITH ... AS ...) |
| Common | WithValues | WITH ... (VALUES ...) inline value lists |
| Common | Returning | RETURNING clause on DML |
| Common | Output | OUTPUT clause (MSSQL's RETURNING equivalent) |
| Common | DefaultPlaceholder | DEFAULT keyword in INSERT value lists |
| Common | DoubleColonCast | PostgreSQL-style :: type cast syntax |
| Common | ValuesRow | VALUES ROW(...) syntax |
| Common | CompositeIn | WHERE (A, B) IN ((N, NN), ...) comparison |
| Common | RowValues | Row-value comparison, e.g. (A, B) > (N, NN) — composite-key keyset pagination |
| SELECT | OffsetFetch | OFFSET ... FETCH NEXT syntax |
| SELECT | SelectExists | EXISTS subquery expressions |
| INSERT | InsertReturning | INSERT ... RETURNING |
| INSERT | InsertTableAlias | Table alias in INSERT statements |
| INSERT | InsertOnConflict | INSERT ... ON CONFLICT |
| INSERT | InsertOnDuplicateKey | INSERT ... ON DUPLICATE KEY |
| INSERT | InsertIgnore | INSERT IGNORE |
| UPDATE | UpdateFromTable | UPDATE ... FROM ... |
| UPDATE | UpdateMultiTable | Multi-table UPDATE syntax |
| UPDATE | UpdateTableAlias | Table alias in UPDATE statements |
| UPDATE | UpdateOrderLimit | UPDATE ... ORDER BY ... LIMIT |
| DELETE | DeleteReturning | DELETE ... RETURNING |
| DELETE | DeleteTableAlias | Table alias in DELETE statements |
| DELETE | DeleteOrderLimit | DELETE ... ORDER BY ... LIMIT |
| MERGE | Merge | MERGE ... USING ... ON ... WHEN |
| MERGE | MergeReturning | MERGE ... RETURNING |
| DDL | TableCascade | CASCADE for DROP TABLE and related operations |
| DDL | TableIdentity | Table-level IDENTITY property |
| DDL | TableTruncate | TRUNCATE TABLE support |
| DDL | TableNotExists | IF NOT EXISTS / IF EXISTS DDL syntax |
| DDL | AlterColumnExists | ADD/DROP COLUMN IF [NOT] EXISTS syntax |
| DDL | CreateIndexIfNotExists | CREATE INDEX IF NOT EXISTS |
| Column | AutoIncrement | AUTO_INCREMENT column syntax |
| Column | Identity | IDENTITY column syntax |
| Column | GeneratedIdentity | GENERATED ALWAYS AS IDENTITY |
| Dialect-specific | FKDefaultOnAction | FK ON UPDATE/ON DELETE defaults to NO ACTION |
| Dialect-specific | Savepoint | SAVEPOINT / ROLLBACK TO / RELEASE (nested transactions) |
| Migrator/catalog | PostgreSQLTypes | PostgreSQL-native type names: BOOLEAN, BIGINT, DOUBLE PRECISION, BYTEA, JSONB |
| Migrator/catalog | InformationSchema | SQL-standard information_schema catalog introspection |
| Migrator/catalog | PragmaTableInfo | SQLite's PRAGMA table_info introspection |
| Migrator/catalog | DollarPlaceholder | $1, $2, ... bind placeholders instead of ? |
| Migrator/catalog | SerialColumn | SERIAL/BIGSERIAL pseudo-types for auto-increment |
| Migrator/catalog | AutoIncrementClause | Requires the AUTOINCREMENT keyword after PRIMARY KEY |
| Migrator/catalog | AlterColumnType | ALTER COLUMN ... TYPE statements |
| Migrator/catalog | AddColumnNonConstantDefault | ALTER TABLE ADD COLUMN with non-constant defaults (CURRENT_TIMESTAMP, function calls) |
The last group's flags exist because migrators introspect the catalog
differently per engine and some DDL loopholes are engine-specific — SQLite
rejects non-constant column defaults outside CREATE TABLE, PostgreSQL
does not.
What each built-in dialect declares
SQLite
// Features declares SQLite's capabilities.
func (d *Dialector) Features() feature.Feature {
return feature.CTE |
feature.WithValues |
feature.Returning |
feature.InsertReturning |
feature.InsertTableAlias |
feature.UpdateTableAlias |
feature.DeleteTableAlias |
feature.InsertOnConflict |
feature.TableNotExists |
feature.SelectExists |
feature.AutoIncrement |
feature.CompositeIn |
feature.RowValues |
feature.FKDefaultOnAction |
feature.DeleteReturning |
feature.CreateIndexIfNotExists |
feature.Savepoint |
feature.PragmaTableInfo |
feature.AutoIncrementClause
}19 flags. Notably absent: DollarPlaceholder (SQLite uses ?),
InformationSchema (introspection goes through PRAGMA table_info
instead), Merge, GeneratedIdentity, and every ...OrderLimit /
multi-table flag.
PostgreSQL
// Features declares PostgreSQL's capabilities.
func (d *Dialector) Features() feature.Feature {
return feature.CTE |
feature.WithValues |
feature.Returning |
feature.InsertReturning |
feature.DefaultPlaceholder |
feature.DoubleColonCast |
feature.InsertTableAlias |
feature.UpdateTableAlias |
feature.DeleteTableAlias |
feature.TableCascade |
feature.TableIdentity |
feature.TableTruncate |
feature.TableNotExists |
feature.InsertOnConflict |
feature.SelectExists |
feature.GeneratedIdentity |
feature.CompositeIn |
feature.RowValues |
feature.FKDefaultOnAction |
feature.DeleteReturning |
feature.Merge |
feature.MergeReturning |
feature.AlterColumnExists |
feature.CreateIndexIfNotExists |
feature.Savepoint |
feature.PostgreSQLTypes |
feature.InformationSchema |
feature.DollarPlaceholder |
feature.SerialColumn |
feature.AlterColumnType |
feature.AddColumnNonConstantDefault
}31 flags. Notably absent: InsertIgnore and InsertOnDuplicateKey
(PostgreSQL upserts via INSERT ... ON CONFLICT), Output,
OffsetFetch, ValuesRow, and the MySQL-style UPDATE ... ORDER BY ... LIMIT family.
Shared core, divergent edges
Both dialects share 16 flags — CTEs, RETURNING, ON CONFLICT, alias
support, exists, composite predicates, savepoints. When a capability
differs (upsert syntax, placeholder style, introspection), the flag set is
what tells the builders — check the tables above before reaching for a
feature in raw Clauses work.
When a flag is missing
Builders that hit an unsupported capability do not guess or degrade
silently. They record a *fusion.UnsupportedFeatureError, which wraps
fusion.ErrUnsupportedFeature and names the missing flag:
// UnsupportedFeatureError names the specific feature flag that a dialect
// lacks, so callers can branch on ErrUnsupportedFeature while still seeing
// which feature was required.
type UnsupportedFeatureError struct {
Feature string
}
func (e *UnsupportedFeatureError) Error() string {
return fmt.Sprintf("unsupported feature: %s", e.Feature)
}For example, starting a nested transaction against a dialect without
Savepoint, or using row-value pagination without RowValues, produces
an error whose Feature field is "Savepoint" / "RowValues" respectively:
tx.AddError(NewUnsupportedFeatureError(feature.Savepoint.Name()))Branch with errors.Is(err, fusion.ErrUnsupportedFeature) and, if needed,
errors.As to read the flag name.