postgres

package
v3.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package postgres implements the PostgreSQL SQL dialect for cel2sql.

Index

Constants

View Source
const (
	IndexTypeBTree = "BTREE"
	IndexTypeGIN   = "GIN"
	IndexTypeGIST  = "GIST"
)

PostgreSQL index type constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect struct{}

Dialect implements dialect.Dialect for PostgreSQL.

func New

func New() *Dialect

New creates a new PostgreSQL dialect.

func (*Dialect) ConvertRegex

func (d *Dialect) ConvertRegex(re2Pattern string) (string, bool, error)

ConvertRegex converts an RE2 regex pattern to PostgreSQL POSIX format.

func (*Dialect) MaxIdentifierLength

func (d *Dialect) MaxIdentifierLength() int

MaxIdentifierLength returns the PostgreSQL maximum identifier length (63).

func (*Dialect) Name

func (d *Dialect) Name() dialect.Name

Name returns the dialect name.

func (*Dialect) RecommendIndex

func (d *Dialect) RecommendIndex(pattern dialect.IndexPattern) *dialect.IndexRecommendation

RecommendIndex generates a PostgreSQL-specific index recommendation for the given pattern. Returns nil if no applicable index exists for this pattern.

func (*Dialect) ReservedKeywords

func (d *Dialect) ReservedKeywords() map[string]bool

ReservedKeywords returns the set of reserved SQL keywords for PostgreSQL.

func (*Dialect) SupportedPatterns

func (d *Dialect) SupportedPatterns() []dialect.PatternType

SupportedPatterns returns all pattern types supported by PostgreSQL.

func (*Dialect) SupportsIndexAnalysis

func (d *Dialect) SupportsIndexAnalysis() bool

SupportsIndexAnalysis returns true as PostgreSQL index analysis is supported.

func (*Dialect) SupportsJSONB

func (d *Dialect) SupportsJSONB() bool

SupportsJSONB returns true as PostgreSQL has a distinct JSONB type.

func (*Dialect) SupportsNativeArrays

func (d *Dialect) SupportsNativeArrays() bool

SupportsNativeArrays returns true as PostgreSQL has native array types.

func (*Dialect) SupportsRegex

func (d *Dialect) SupportsRegex() bool

SupportsRegex returns true as PostgreSQL supports POSIX regex matching.

func (*Dialect) ValidateFieldName

func (d *Dialect) ValidateFieldName(name string) error

ValidateFieldName validates a field name against PostgreSQL naming rules.

func (*Dialect) WriteArrayLength

func (d *Dialect) WriteArrayLength(w *strings.Builder, dimension int, writeExpr func() error) error

WriteArrayLength writes COALESCE(ARRAY_LENGTH(expr, dimension), 0) for PostgreSQL.

func (*Dialect) WriteArrayLiteralClose

func (d *Dialect) WriteArrayLiteralClose(w *strings.Builder)

WriteArrayLiteralClose writes the PostgreSQL array literal closing (]).

func (*Dialect) WriteArrayLiteralOpen

func (d *Dialect) WriteArrayLiteralOpen(w *strings.Builder)

WriteArrayLiteralOpen writes the PostgreSQL array literal opening (ARRAY[).

func (*Dialect) WriteArrayMembership

func (d *Dialect) WriteArrayMembership(w *strings.Builder, writeElem func() error, writeArray func() error) error

WriteArrayMembership writes a PostgreSQL array membership test using = ANY().

func (*Dialect) WriteArraySubqueryExprClose

func (d *Dialect) WriteArraySubqueryExprClose(_ *strings.Builder)

WriteArraySubqueryExprClose is a no-op for PostgreSQL (no wrapper around the expression).

func (*Dialect) WriteArraySubqueryOpen

func (d *Dialect) WriteArraySubqueryOpen(w *strings.Builder)

WriteArraySubqueryOpen writes ARRAY(SELECT for PostgreSQL.

func (*Dialect) WriteBytesLiteral

func (d *Dialect) WriteBytesLiteral(w *strings.Builder, value []byte) error

WriteBytesLiteral writes a PostgreSQL hex-encoded byte literal.

func (*Dialect) WriteCastToNumeric

func (d *Dialect) WriteCastToNumeric(w *strings.Builder)

WriteCastToNumeric writes a PostgreSQL numeric cast suffix (::numeric).

func (*Dialect) WriteContains

func (d *Dialect) WriteContains(w *strings.Builder, writeHaystack, writeNeedle func() error) error

WriteContains writes POSITION(needle IN haystack) > 0 for PostgreSQL.

func (*Dialect) WriteDuration

func (d *Dialect) WriteDuration(w *strings.Builder, value int64, unit string)

WriteDuration writes a PostgreSQL INTERVAL literal (INTERVAL N UNIT).

func (*Dialect) WriteEmptyTypedArray

func (d *Dialect) WriteEmptyTypedArray(w *strings.Builder, typeName string)

WriteEmptyTypedArray writes an empty PostgreSQL typed array (ARRAY[]::type[]).

func (*Dialect) WriteEpochExtract

func (d *Dialect) WriteEpochExtract(w *strings.Builder, writeExpr func() error) error

WriteEpochExtract writes EXTRACT(EPOCH FROM expr)::bigint for PostgreSQL.

func (*Dialect) WriteExtract

func (d *Dialect) WriteExtract(w *strings.Builder, part string, writeExpr func() error, writeTZ func() error) error

WriteExtract writes a PostgreSQL EXTRACT expression with DOW conversion.

func (*Dialect) WriteInterval

func (d *Dialect) WriteInterval(w *strings.Builder, writeValue func() error, unit string) error

WriteInterval writes a PostgreSQL INTERVAL expression (INTERVAL expr UNIT).

func (*Dialect) WriteJSONArrayElements

func (d *Dialect) WriteJSONArrayElements(w *strings.Builder, isJSONB bool, asText bool, writeExpr func() error) error

WriteJSONArrayElements writes a PostgreSQL JSON array expansion function.

func (*Dialect) WriteJSONArrayLength

func (d *Dialect) WriteJSONArrayLength(w *strings.Builder, writeExpr func() error) error

WriteJSONArrayLength writes COALESCE(jsonb_array_length(expr), 0) for PostgreSQL.

func (*Dialect) WriteJSONArrayMembership

func (d *Dialect) WriteJSONArrayMembership(w *strings.Builder, jsonFunc string, writeExpr func() error) error

WriteJSONArrayMembership writes ANY(ARRAY(SELECT json_func(expr))) for PostgreSQL.

func (*Dialect) WriteJSONExistence

func (d *Dialect) WriteJSONExistence(w *strings.Builder, isJSONB bool, fieldName string, writeBase func() error) error

WriteJSONExistence writes a PostgreSQL JSON key existence check (? or IS NOT NULL).

func (*Dialect) WriteJSONExtractPath

func (d *Dialect) WriteJSONExtractPath(w *strings.Builder, pathSegments []string, writeRoot func() error) error

WriteJSONExtractPath writes jsonb_extract_path_text() IS NOT NULL for PostgreSQL.

func (*Dialect) WriteJSONFieldAccess

func (d *Dialect) WriteJSONFieldAccess(w *strings.Builder, writeBase func() error, fieldName string, isFinal bool) error

WriteJSONFieldAccess writes PostgreSQL JSON field access using -> or ->> operators.

func (*Dialect) WriteJoin

func (d *Dialect) WriteJoin(w *strings.Builder, writeArray, writeDelim func() error) error

WriteJoin writes ARRAY_TO_STRING(array, delimiter, ”) for PostgreSQL.

func (*Dialect) WriteLikeEscape

func (d *Dialect) WriteLikeEscape(w *strings.Builder)

WriteLikeEscape writes the PostgreSQL LIKE escape clause.

func (*Dialect) WriteListIndex

func (d *Dialect) WriteListIndex(w *strings.Builder, writeArray func() error, writeIndex func() error) error

WriteListIndex writes a PostgreSQL 1-indexed array access (array[index + 1]).

func (*Dialect) WriteListIndexConst

func (d *Dialect) WriteListIndexConst(w *strings.Builder, writeArray func() error, index int64) error

WriteListIndexConst writes a PostgreSQL constant array index (0-indexed to 1-indexed).

func (*Dialect) WriteNestedJSONArrayMembership

func (d *Dialect) WriteNestedJSONArrayMembership(w *strings.Builder, writeExpr func() error) error

WriteNestedJSONArrayMembership writes ANY(ARRAY(SELECT jsonb_array_elements_text(expr))) for PostgreSQL.

func (*Dialect) WriteParamPlaceholder

func (d *Dialect) WriteParamPlaceholder(w *strings.Builder, paramIndex int)

WriteParamPlaceholder writes a PostgreSQL positional parameter ($1, $2, ...).

func (*Dialect) WriteRegexMatch

func (d *Dialect) WriteRegexMatch(w *strings.Builder, writeTarget func() error, pattern string, caseInsensitive bool) error

WriteRegexMatch writes a PostgreSQL regex match using ~ or ~* operators.

func (*Dialect) WriteSplit

func (d *Dialect) WriteSplit(w *strings.Builder, writeStr, writeDelim func() error) error

WriteSplit writes STRING_TO_ARRAY(string, delimiter) for PostgreSQL.

func (*Dialect) WriteSplitWithLimit

func (d *Dialect) WriteSplitWithLimit(w *strings.Builder, writeStr, writeDelim func() error, limit int64) error

WriteSplitWithLimit writes (STRING_TO_ARRAY(string, delimiter))[1:limit] for PostgreSQL.

func (*Dialect) WriteStringConcat

func (d *Dialect) WriteStringConcat(w *strings.Builder, writeLHS, writeRHS func() error) error

WriteStringConcat writes a PostgreSQL string concatenation using ||.

func (*Dialect) WriteStringLiteral

func (d *Dialect) WriteStringLiteral(w *strings.Builder, value string)

WriteStringLiteral writes a PostgreSQL string literal with ” escaping.

func (*Dialect) WriteStructClose

func (d *Dialect) WriteStructClose(w *strings.Builder)

WriteStructClose writes the PostgreSQL struct/row literal closing ()).

func (*Dialect) WriteStructOpen

func (d *Dialect) WriteStructOpen(w *strings.Builder)

WriteStructOpen writes the PostgreSQL struct/row literal opening (ROW().

func (*Dialect) WriteTimestampArithmetic

func (d *Dialect) WriteTimestampArithmetic(w *strings.Builder, op string, writeTS, writeDur func() error) error

WriteTimestampArithmetic writes PostgreSQL timestamp arithmetic (timestamp +/- interval).

func (*Dialect) WriteTimestampCast

func (d *Dialect) WriteTimestampCast(w *strings.Builder, writeExpr func() error) error

WriteTimestampCast writes CAST(expr AS TIMESTAMP WITH TIME ZONE) for PostgreSQL.

func (*Dialect) WriteTypeName

func (d *Dialect) WriteTypeName(w *strings.Builder, celTypeName string)

WriteTypeName writes a PostgreSQL type name for CAST expressions.

func (*Dialect) WriteUnnest

func (d *Dialect) WriteUnnest(w *strings.Builder, writeSource func() error) error

WriteUnnest writes UNNEST(source) for PostgreSQL comprehensions.

Jump to

Keyboard shortcuts

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