Dialects

SQLSpec registers custom sqlglot dialects that extend built-in SQL grammars with extension-specific operators. These dialects enable the builder to parse and generate SQL that uses vendor-specific syntax (e.g., pgvector distance operators, ParadeDB search operators).

Import sqlspec.dialects to ensure all dialects are registered:

import sqlspec.dialects  # registers pgvector, paradedb, spanner, spangres

PostgreSQL Extensions

PGVector

Adds support for pgvector distance operators:

Operator

Description

<->

L2 (Euclidean) distance

<#>

Negative inner product

<=>

Cosine distance

<+>

L1 (Manhattan) distance

<~>

Hamming distance (binary vectors)

<%>

Jaccard distance (binary vectors)

ParadeDB

Extends PGVector with ParadeDB pg_search operators:

Operator

Description

@@@

BM25 full-text search

&&&

Boolean AND search

|||

Boolean OR search

===

Exact term match

###

Score/rank retrieval

##

Snippet/highlight retrieval

##>

Snippet/highlight with options

Spanner

class sqlspec.dialects.spanner.Spanner[source]

Bases: BigQuery

Google Cloud Spanner SQL dialect.

Tokenizer

alias of SpannerTokenizer

parse(sql, **opts)[source]

Repair CREATE TABLE statements that sqlglot still falls back to Command for.

Return type:

list[Expr | None]

BYTE_STRINGS_SUPPORT_ESCAPED_SEQUENCES: bool = True

Whether byte string literals support escape sequences. Set by the metaclass based on the tokenizer's BYTE_STRING_ESCAPES.

STRINGS_SUPPORT_ESCAPED_SEQUENCES: bool = True

Whether string literals support escape sequences (e.g. n). Set by the metaclass based on the tokenizer's STRING_ESCAPES.

SUPPORTS_COLUMN_JOIN_MARKS = False

Whether the old-style outer join (+) syntax is supported.

UNESCAPED_SEQUENCES: dict[str, str] = {'\\\\': '\\', '\\a': '\x07', '\\b': '\x08', '\\f': '\x0c', '\\n': '\n', '\\r': '\r', '\\t': '\t', '\\v': '\x0b'}

Mapping of an escaped sequence (n) to its unescaped version (` `).

tokenizer_class

alias of SpannerTokenizer

class sqlspec.dialects.spanner.Spangres[source]

Bases: Postgres

Spanner PostgreSQL-compatible dialect.

BYTE_STRINGS_SUPPORT_ESCAPED_SEQUENCES: bool = False

Whether byte string literals support escape sequences. Set by the metaclass based on the tokenizer's BYTE_STRING_ESCAPES.

STRINGS_SUPPORT_ESCAPED_SEQUENCES: bool = False

Whether string literals support escape sequences (e.g. n). Set by the metaclass based on the tokenizer's STRING_ESCAPES.

SUPPORTS_COLUMN_JOIN_MARKS = False

Whether the old-style outer join (+) syntax is supported.

Expression Types

sqlspec.builder.VectorDistance(*, this, expression, metric='euclidean')[source]

Build a SQLSpec vector-distance expression.

Return type:

Operator