dialect

package
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package dialect provides typed SQL dialect identity and capability flags for GoSQLX. Use Capabilities() on a Dialect to feature-gate parser logic instead of string comparisons such as `p.dialect == "postgresql"`.

The typed Dialect constants in this package are the long-term replacement for scattered `p.dialect == "..."` comparisons in the parser. Consumers should prefer Dialect / Capabilities over string comparison so that:

  • typos are caught at compile time;
  • adding a new dialect is a single-file change (adding a case to Capabilities()) rather than a grep-audit of dozens of parser files;
  • feature detection is intent-revealing ("supports QUALIFY") rather than implementation-coupled ("is Snowflake or BigQuery").

Backward compatibility:

  • The parser.Parser struct keeps its string `dialect` field and its string-returning Dialect() method for the v1.x series.
  • Migration happens call-site by call-site as scheduled for v2.0.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capabilities

type Capabilities struct {

	// SupportsQualify indicates QUALIFY clause support
	// (Snowflake, BigQuery, Databricks, DuckDB).
	SupportsQualify bool

	// SupportsArrayJoin indicates ARRAY JOIN clause support (ClickHouse).
	SupportsArrayJoin bool

	// SupportsPrewhere indicates PREWHERE clause support (ClickHouse).
	SupportsPrewhere bool

	// SupportsSample indicates SAMPLE / TABLESAMPLE clause support
	// (ClickHouse SAMPLE, standard TABLESAMPLE in PostgreSQL, SQL Server,
	// Snowflake).
	SupportsSample bool

	// SupportsTimeTravel indicates AT/BEFORE time-travel clauses
	// (Snowflake AT/BEFORE, Oracle FLASHBACK).
	SupportsTimeTravel bool

	// SupportsMatchRecognize indicates MATCH_RECOGNIZE row-pattern
	// recognition (Oracle 12c+, Snowflake, Trino).
	SupportsMatchRecognize bool

	// SupportsPivotUnpivot indicates PIVOT / UNPIVOT support
	// (Oracle 11g+, SQL Server, Snowflake, Databricks).
	SupportsPivotUnpivot bool

	// SupportsWindowIgnoreNulls indicates IGNORE NULLS / RESPECT NULLS in
	// window functions (Oracle, Snowflake, SQL Server, Redshift, BigQuery).
	SupportsWindowIgnoreNulls bool

	// SupportsConnectBy indicates CONNECT BY / START WITH hierarchical
	// queries (Oracle, Snowflake, MariaDB 10.2+).
	SupportsConnectBy bool

	// SupportsTop indicates TOP N row limiting
	// (SQL Server, Snowflake, Sybase).
	SupportsTop bool

	// SupportsLimitOffset indicates LIMIT / OFFSET row limiting
	// (PostgreSQL, MySQL, MariaDB, SQLite, ClickHouse, Snowflake,
	// BigQuery, Redshift).
	SupportsLimitOffset bool

	// SupportsFetchFirst indicates standard SQL FETCH FIRST / OFFSET
	// (Oracle 12c+, SQL Server 2012+, PostgreSQL, DB2).
	SupportsFetchFirst bool

	// SupportsMerge indicates MERGE statement support
	// (SQL Server, Oracle, Snowflake, PostgreSQL 15+, BigQuery,
	// ClickHouse 23.3+, MariaDB; NOT SQLite or classic MySQL).
	SupportsMerge bool

	// SupportsReturning indicates RETURNING clause on DML
	// (PostgreSQL, Oracle, SQLite 3.35+, MariaDB, BigQuery).
	SupportsReturning bool

	// SupportsCompoundReturning indicates the SQL Server OUTPUT clause,
	// which is similar to RETURNING but has different syntax and can emit
	// into a result set or a table.
	SupportsCompoundReturning bool

	// SupportsDistinctOn indicates SELECT DISTINCT ON (...) syntax
	// (PostgreSQL-only, not standard SQL).
	SupportsDistinctOn bool

	// SupportsMaterializedView indicates MATERIALIZED VIEW DDL
	// (PostgreSQL, Oracle, Snowflake, ClickHouse, Redshift, BigQuery,
	// Databricks).
	SupportsMaterializedView bool

	// SupportsIndexHints indicates MySQL-style USE INDEX / FORCE INDEX /
	// IGNORE INDEX table hints (MySQL, MariaDB).
	SupportsIndexHints bool

	// SupportsBracketQuoting indicates [column] identifier quoting
	// (SQL Server, MS Access).
	SupportsBracketQuoting bool

	// SupportsBacktickQuoting indicates `column` identifier quoting
	// (MySQL, MariaDB, ClickHouse, BigQuery, Snowflake for some contexts).
	SupportsBacktickQuoting bool

	// SupportsDoubleQuoteIdentifier indicates "column" as identifier
	// (standard SQL; supported by PostgreSQL, Oracle, SQLite, DB2,
	// Snowflake, Redshift, and SQL Server with QUOTED_IDENTIFIER ON).
	SupportsDoubleQuoteIdentifier bool

	// SupportsILike indicates case-insensitive LIKE via the ILIKE operator
	// (PostgreSQL, Snowflake, DuckDB, Redshift).
	SupportsILike bool
}

Capabilities describes which optional SQL features a dialect supports. This is the long-term replacement for scattered `p.dialect == "..."` string comparisons in the parser.

Fields are intentionally kept to genuine feature-gated capabilities: each flag should correspond to at least one existing parser branch that would otherwise require string comparison. If a feature is supported by every dialect (e.g. SELECT, basic WHERE), it does not belong here.

type Dialect

type Dialect string

Dialect is a typed SQL dialect identifier. The zero value is Unknown (empty string), which means "no dialect specified" and selects the permissive default capability set.

const (
	// Unknown is the zero value; no dialect has been explicitly selected.
	// Matches the behaviour of an empty parser.dialect string field and
	// yields the permissive default capability set.
	Unknown Dialect = ""

	// PostgreSQL is the PostgreSQL dialect (https://www.postgresql.org/docs/).
	PostgreSQL Dialect = "postgresql"

	// MySQL is the MySQL / Percona dialect (https://dev.mysql.com/doc/).
	MySQL Dialect = "mysql"

	// MariaDB is the MariaDB dialect (https://mariadb.com/kb/en/).
	// Superset of MySQL 5.7 syntax plus SEQUENCE, system-versioned tables,
	// CONNECT BY, and index visibility controls.
	MariaDB Dialect = "mariadb"

	// SQLServer is Microsoft SQL Server / T-SQL
	// (https://learn.microsoft.com/sql/t-sql/).
	SQLServer Dialect = "sqlserver"

	// Oracle is Oracle Database / PL-SQL
	// (https://docs.oracle.com/en/database/oracle/oracle-database/).
	Oracle Dialect = "oracle"

	// SQLite is SQLite (https://www.sqlite.org/lang.html).
	SQLite Dialect = "sqlite"

	// Snowflake is Snowflake (https://docs.snowflake.com/).
	Snowflake Dialect = "snowflake"

	// ClickHouse is ClickHouse (https://clickhouse.com/docs/).
	ClickHouse Dialect = "clickhouse"

	// BigQuery is Google BigQuery
	// (https://cloud.google.com/bigquery/docs/reference/standard-sql/).
	BigQuery Dialect = "bigquery"

	// Redshift is Amazon Redshift
	// (https://docs.aws.amazon.com/redshift/latest/dg/).
	Redshift Dialect = "redshift"

	// Generic represents standard/ANSI SQL with no dialect-specific
	// features. It is distinct from Unknown: Generic explicitly means
	// "parse standard SQL only"; Unknown means "no choice has been made".
	Generic Dialect = "generic"
)

Dialect constants. String values match the keywords.SQLDialect values to allow round-tripping through the legacy string field on the parser.

func Parse

func Parse(s string) Dialect

Parse normalises a free-form dialect string to a typed Dialect. The match is case-insensitive and tolerates a short list of well-known aliases ("postgres" -> PostgreSQL, "mssql" -> SQLServer). Unknown strings map to Unknown.

Empty input returns Unknown.

func (Dialect) Capabilities

func (d Dialect) Capabilities() Capabilities

Capabilities returns the capability matrix for d.

For Unknown, the returned Capabilities is the "permissive default": flags that correspond to widely-supported standard SQL features are enabled so that callers who never call WithDialect keep working. Dialect-specific extensions (QUALIFY, ARRAY JOIN, PREWHERE, etc.) are disabled in the permissive default.

func (Dialect) IsValid

func (d Dialect) IsValid() bool

IsValid reports whether d is a recognised dialect (not Unknown).

func (Dialect) String

func (d Dialect) String() string

String satisfies fmt.Stringer. Returns the canonical lowercase dialect identifier, or the empty string for Unknown.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL