Module: Sqlglot::Dialect

Defined in:
lib/sqlglot/dialect.rb

Overview

Constants for all 30 SQL dialects supported by sql-glot-rust.

Each constant holds the string name passed to the Rust FFI. Use symbols or strings interchangeably in the public API – Dialect.resolve normalizes them.

Examples:

Sqlglot.transpile(sql, from: Sqlglot::Dialect::POSTGRES, to: Sqlglot::Dialect::BIGQUERY)
Sqlglot.transpile(sql, from: :postgres, to: :bigquery)  # same thing

Constant Summary collapse

ANSI =

── Official dialects ──────────────────────────────────────

"ansi"
ATHENA =
"athena"
BIGQUERY =
"bigquery"
CLICKHOUSE =
"clickhouse"
DATABRICKS =
"databricks"
DUCKDB =
"duckdb"
HIVE =
"hive"
MYSQL =
"mysql"
ORACLE =
"oracle"
POSTGRES =
"postgres"
PRESTO =
"presto"
REDSHIFT =
"redshift"
SNOWFLAKE =
"snowflake"
SPARK =
"spark"
SQLITE =
"sqlite"
STARROCKS =
"starrocks"
TRINO =
"trino"
TSQL =
"tsql"
DORIS =

── Community dialects ─────────────────────────────────────

"doris"
DREMIO =
"dremio"
DRILL =
"drill"
DRUID =
"druid"
EXASOL =
"exasol"
FABRIC =
"fabric"
MATERIALIZE =
"materialize"
PRQL =
"prql"
RISINGWAVE =
"risingwave"
SINGLESTORE =
"singlestore"
TABLEAU =
"tableau"
TERADATA =
"teradata"
ALIASES =

Common aliases accepted by the Rust library’s Dialect::from_str.

{
  "postgresql" => POSTGRES,
  "mssql"      => TSQL,
  "sqlserver"  => TSQL,
  "mariadb"    => MYSQL,
}.freeze
ALL =

All known dialect names (constants + aliases).

constants
.reject { |c| %i[ALIASES ALL].include?(c) }
.map { |c| const_get(c) }
.freeze

Class Method Summary collapse

Class Method Details

.resolve(name) ⇒ String?

Normalize a dialect argument to the string the Rust FFI expects.

Accepts symbols, strings, or nil. Unknown values raise ArgumentError.

Parameters:

  • name (Symbol, String, nil)

Returns:

  • (String, nil)

    the dialect string, or nil if name is nil

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
75
76
77
# File 'lib/sqlglot/dialect.rb', line 68

def self.resolve(name)
  return nil if name.nil?

  key = name.to_s.downcase.strip
  return key if ALL.include?(key)
  return ALIASES[key] if ALIASES.key?(key)

  raise ArgumentError, "Unknown dialect: #{name.inspect}. " \
                       "Known dialects: #{ALL.sort.join(', ')}"
end