Documentation ¶
Index ¶
- Variables
- func AddAssignmentTypeCast(cast TypeCast) error
- func AddExplicitTypeCast(cast TypeCast) error
- func AddImplicitTypeCast(cast TypeCast) error
- func FindCommonType(types []pgtypes.DoltgresTypeBaseID) (pgtypes.DoltgresTypeBaseID, error)
- func GetPotentialAssignmentCasts(fromType pgtypes.DoltgresTypeBaseID) []pgtypes.DoltgresType
- func GetPotentialExplicitCasts(fromType pgtypes.DoltgresTypeBaseID) []pgtypes.DoltgresType
- func GetPotentialImplicitCasts(fromType pgtypes.DoltgresTypeBaseID) []pgtypes.DoltgresType
- func Initialize()
- func MustAddAssignmentTypeCast(cast TypeCast)
- func MustAddExplicitTypeCast(cast TypeCast)
- func MustAddImplicitTypeCast(cast TypeCast)
- func RegisterBinaryFunction(operator Operator, f Function2)
- func RegisterFunction(f FunctionInterface)
- func RegisterUnaryFunction(operator Operator, f Function1)
- func UnknownLiteralCast(ctx *sql.Context, val any, targetType pgtypes.DoltgresType) (any, error)
- type CompiledFunction
- func (c *CompiledFunction) Children() []sql.Expression
- func (c *CompiledFunction) Description() string
- func (c *CompiledFunction) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
- func (c *CompiledFunction) FunctionName() string
- func (c *CompiledFunction) IsNonDeterministic() bool
- func (c *CompiledFunction) IsNullable() bool
- func (c *CompiledFunction) OverloadString(types []pgtypes.DoltgresType) string
- func (c *CompiledFunction) Resolved() bool
- func (c *CompiledFunction) StashedError() error
- func (c *CompiledFunction) String() string
- func (c *CompiledFunction) Type() sql.Type
- func (c *CompiledFunction) WithChildren(children ...sql.Expression) (sql.Expression, error)
- type Function0
- func (f Function0) GetExpectedParameterCount() int
- func (f Function0) GetName() string
- func (f Function0) GetParameters() []pgtypes.DoltgresType
- func (f Function0) GetReturn() pgtypes.DoltgresType
- func (f Function0) IsStrict() bool
- func (f Function0) NonDeterministic() bool
- func (f Function0) VariadicIndex() int
- type Function1
- func (f Function1) GetExpectedParameterCount() int
- func (f Function1) GetName() string
- func (f Function1) GetParameters() []pgtypes.DoltgresType
- func (f Function1) GetReturn() pgtypes.DoltgresType
- func (f Function1) IsStrict() bool
- func (f Function1) NonDeterministic() bool
- func (f Function1) VariadicIndex() int
- type Function2
- func (f Function2) GetExpectedParameterCount() int
- func (f Function2) GetName() string
- func (f Function2) GetParameters() []pgtypes.DoltgresType
- func (f Function2) GetReturn() pgtypes.DoltgresType
- func (f Function2) IsStrict() bool
- func (f Function2) NonDeterministic() bool
- func (f Function2) VariadicIndex() int
- type Function3
- func (f Function3) GetExpectedParameterCount() int
- func (f Function3) GetName() string
- func (f Function3) GetParameters() []pgtypes.DoltgresType
- func (f Function3) GetReturn() pgtypes.DoltgresType
- func (f Function3) IsStrict() bool
- func (f Function3) NonDeterministic() bool
- func (f Function3) VariadicIndex() int
- type Function4
- func (f Function4) GetExpectedParameterCount() int
- func (f Function4) GetName() string
- func (f Function4) GetParameters() []pgtypes.DoltgresType
- func (f Function4) GetReturn() pgtypes.DoltgresType
- func (f Function4) IsStrict() bool
- func (f Function4) NonDeterministic() bool
- func (f Function4) VariadicIndex() int
- type FunctionInterface
- type IntermediateFunction
- type LiteralInterface
- type Operator
- type Overload
- type Overloads
- type TypeCast
- type TypeCastFunction
- func GetAssignmentCast(fromType pgtypes.DoltgresTypeBaseID, toType pgtypes.DoltgresTypeBaseID) TypeCastFunction
- func GetExplicitCast(fromType pgtypes.DoltgresTypeBaseID, toType pgtypes.DoltgresTypeBaseID) TypeCastFunction
- func GetImplicitCast(fromType pgtypes.DoltgresTypeBaseID, toType pgtypes.DoltgresTypeBaseID) TypeCastFunction
Constants ¶
This section is empty.
Variables ¶
var Catalog = map[string][]FunctionInterface{}
Catalog contains all of the PostgreSQL functions.
Functions ¶
func AddAssignmentTypeCast ¶ added in v0.8.0
AddAssignmentTypeCast registers the given assignment type cast.
func AddExplicitTypeCast ¶ added in v0.6.0
AddExplicitTypeCast registers the given explicit type cast.
func AddImplicitTypeCast ¶ added in v0.6.0
AddImplicitTypeCast registers the given implicit type cast.
func FindCommonType ¶ added in v0.11.1
func FindCommonType(types []pgtypes.DoltgresTypeBaseID) (pgtypes.DoltgresTypeBaseID, error)
FindCommonType returns the common type that given types can convert to. https://www.postgresql.org/docs/15/typeconv-union-case.html
func GetPotentialAssignmentCasts ¶ added in v0.8.0
func GetPotentialAssignmentCasts(fromType pgtypes.DoltgresTypeBaseID) []pgtypes.DoltgresType
GetPotentialAssignmentCasts returns all registered assignment and implicit type casts from the given type.
func GetPotentialExplicitCasts ¶ added in v0.6.0
func GetPotentialExplicitCasts(fromType pgtypes.DoltgresTypeBaseID) []pgtypes.DoltgresType
GetPotentialExplicitCasts returns all registered explicit type casts from the given type.
func GetPotentialImplicitCasts ¶ added in v0.6.0
func GetPotentialImplicitCasts(fromType pgtypes.DoltgresTypeBaseID) []pgtypes.DoltgresType
GetPotentialImplicitCasts returns all registered implicit type casts from the given type.
func Initialize ¶
func Initialize()
Initialize handles the initialization of the catalog by overwriting the built-in GMS functions, since they do not apply to PostgreSQL (and functions of the same name often have different behavior).
func MustAddAssignmentTypeCast ¶ added in v0.8.0
func MustAddAssignmentTypeCast(cast TypeCast)
MustAddAssignmentTypeCast registers the given assignment type cast. Panics if an error occurs.
func MustAddExplicitTypeCast ¶ added in v0.6.0
func MustAddExplicitTypeCast(cast TypeCast)
MustAddExplicitTypeCast registers the given explicit type cast. Panics if an error occurs.
func MustAddImplicitTypeCast ¶ added in v0.6.0
func MustAddImplicitTypeCast(cast TypeCast)
MustAddImplicitTypeCast registers the given implicit type cast. Panics if an error occurs.
func RegisterBinaryFunction ¶
RegisterBinaryFunction registers the given function, so that it will be usable from a running server. This should only be used for binary functions, which are the underlying functions for binary operators such as addition, subtraction, etc. This should be called from within an init().
func RegisterFunction ¶
func RegisterFunction(f FunctionInterface)
RegisterFunction registers the given function, so that it will be usable from a running server. This should be called from within an init().
func RegisterUnaryFunction ¶
RegisterUnaryFunction registers the given function, so that it will be usable from a running server. This should only be used for unary functions, which are the underlying functions for unary operators such as negation, etc. This should be called from within an init().
func UnknownLiteralCast ¶ added in v0.13.0
UnknownLiteralCast is used when casting from an unknown literal to any type, as unknown literals are treated special in some contexts.
Types ¶
type CompiledFunction ¶
type CompiledFunction struct { Name string Arguments []sql.Expression IsOperator bool // contains filtered or unexported fields }
CompiledFunction is an expression that represents a fully-analyzed PostgreSQL function.
func GetFunction ¶ added in v0.8.0
func GetFunction(functionName string, params ...sql.Expression) (*CompiledFunction, bool, error)
GetFunction returns the compiled function with the given name and parameters. Returns false if the function could not be found.
func NewCompiledFunction ¶ added in v0.9.0
func NewCompiledFunction(name string, args []sql.Expression, functions *Overloads, isOperator bool) *CompiledFunction
NewCompiledFunction returns a newly compiled function.
func (*CompiledFunction) Children ¶
func (c *CompiledFunction) Children() []sql.Expression
Children implements the interface sql.Expression.
func (*CompiledFunction) Description ¶
func (c *CompiledFunction) Description() string
Description implements the interface sql.Expression.
func (*CompiledFunction) FunctionName ¶
func (c *CompiledFunction) FunctionName() string
FunctionName implements the interface sql.Expression.
func (*CompiledFunction) IsNonDeterministic ¶ added in v0.8.0
func (c *CompiledFunction) IsNonDeterministic() bool
IsNonDeterministic implements the interface sql.NonDeterministicExpression.
func (*CompiledFunction) IsNullable ¶
func (c *CompiledFunction) IsNullable() bool
IsNullable implements the interface sql.Expression.
func (*CompiledFunction) OverloadString ¶
func (c *CompiledFunction) OverloadString(types []pgtypes.DoltgresType) string
OverloadString returns the name of the function represented by the given overload.
func (*CompiledFunction) Resolved ¶
func (c *CompiledFunction) Resolved() bool
Resolved implements the interface sql.Expression.
func (*CompiledFunction) StashedError ¶ added in v0.12.0
func (c *CompiledFunction) StashedError() error
StashedError returns the stashed error if one exists. Otherwise, returns nil.
func (*CompiledFunction) String ¶
func (c *CompiledFunction) String() string
String implements the interface sql.Expression.
func (*CompiledFunction) Type ¶
func (c *CompiledFunction) Type() sql.Type
Type implements the interface sql.Expression.
func (*CompiledFunction) WithChildren ¶
func (c *CompiledFunction) WithChildren(children ...sql.Expression) (sql.Expression, error)
WithChildren implements the interface sql.Expression.
type Function0 ¶
type Function0 struct { Name string Return pgtypes.DoltgresType IsNonDeterministic bool Strict bool Callable func(ctx *sql.Context) (any, error) }
Function0 is a function that does not take any parameters.
func (Function0) GetExpectedParameterCount ¶
GetExpectedParameterCount implements the FunctionInterface interface.
func (Function0) GetParameters ¶
func (f Function0) GetParameters() []pgtypes.DoltgresType
GetParameters implements the FunctionInterface interface.
func (Function0) GetReturn ¶
func (f Function0) GetReturn() pgtypes.DoltgresType
GetReturn implements the FunctionInterface interface.
func (Function0) NonDeterministic ¶ added in v0.11.0
NonDeterministic implements the FunctionInterface interface.
func (Function0) VariadicIndex ¶ added in v0.11.0
type Function1 ¶
type Function1 struct { Name string Return pgtypes.DoltgresType Parameters [1]pgtypes.DoltgresType Variadic bool IsNonDeterministic bool Strict bool Callable func(ctx *sql.Context, paramsAndReturn [2]pgtypes.DoltgresType, val1 any) (any, error) }
Function1 is a function that takes one parameter. The parameter and return type is passed into the Callable function when the parameter (and possibly return type) is a polymorphic type. The return type is the last type in the array.
func (Function1) GetExpectedParameterCount ¶
GetExpectedParameterCount implements the FunctionInterface interface.
func (Function1) GetParameters ¶
func (f Function1) GetParameters() []pgtypes.DoltgresType
GetParameters implements the FunctionInterface interface.
func (Function1) GetReturn ¶
func (f Function1) GetReturn() pgtypes.DoltgresType
GetReturn implements the FunctionInterface interface.
func (Function1) NonDeterministic ¶ added in v0.11.0
NonDeterministic implements the FunctionInterface interface.
func (Function1) VariadicIndex ¶ added in v0.11.0
VariadicIndex implements the FunctionInterface interface.
type Function2 ¶
type Function2 struct { Name string Return pgtypes.DoltgresType Parameters [2]pgtypes.DoltgresType Variadic bool IsNonDeterministic bool Strict bool Callable func(ctx *sql.Context, paramsAndReturn [3]pgtypes.DoltgresType, val1 any, val2 any) (any, error) }
Function2 is a function that takes two parameters. The parameter and return types are passed into the Callable function when the parameters (and possibly return type) have at least one polymorphic type. The return type is the last type in the array.
func (Function2) GetExpectedParameterCount ¶
GetExpectedParameterCount implements the FunctionInterface interface.
func (Function2) GetParameters ¶
func (f Function2) GetParameters() []pgtypes.DoltgresType
GetParameters implements the FunctionInterface interface.
func (Function2) GetReturn ¶
func (f Function2) GetReturn() pgtypes.DoltgresType
GetReturn implements the FunctionInterface interface.
func (Function2) NonDeterministic ¶ added in v0.11.0
NonDeterministic implements the FunctionInterface interface.
func (Function2) VariadicIndex ¶ added in v0.11.0
VariadicIndex implements the FunctionInterface interface.
type Function3 ¶
type Function3 struct { Name string Return pgtypes.DoltgresType Parameters [3]pgtypes.DoltgresType Variadic bool IsNonDeterministic bool Strict bool Callable func(ctx *sql.Context, paramsAndReturn [4]pgtypes.DoltgresType, val1 any, val2 any, val3 any) (any, error) }
Function3 is a function that takes three parameters. The parameter and return types are passed into the Callable function when the parameters (and possibly return type) have at least one polymorphic type. The return type is the last type in the array.
func (Function3) GetExpectedParameterCount ¶
GetExpectedParameterCount implements the FunctionInterface interface.
func (Function3) GetParameters ¶
func (f Function3) GetParameters() []pgtypes.DoltgresType
GetParameters implements the FunctionInterface interface.
func (Function3) GetReturn ¶
func (f Function3) GetReturn() pgtypes.DoltgresType
GetReturn implements the FunctionInterface interface.
func (Function3) NonDeterministic ¶ added in v0.11.0
NonDeterministic implements the FunctionInterface interface.
func (Function3) VariadicIndex ¶ added in v0.11.0
VariadicIndex implements the FunctionInterface interface.
type Function4 ¶
type Function4 struct { Name string Return pgtypes.DoltgresType Parameters [4]pgtypes.DoltgresType Variadic bool IsNonDeterministic bool Strict bool Callable func(ctx *sql.Context, paramsAndReturn [5]pgtypes.DoltgresType, val1 any, val2 any, val3 any, val4 any) (any, error) }
Function4 is a function that takes four parameters. The parameter and return types are passed into the Callable function when the parameters (and possibly return type) have at least one polymorphic type. The return type is the last type in the array.
func (Function4) GetExpectedParameterCount ¶
GetExpectedParameterCount implements the FunctionInterface interface.
func (Function4) GetParameters ¶
func (f Function4) GetParameters() []pgtypes.DoltgresType
GetParameters implements the FunctionInterface interface.
func (Function4) GetReturn ¶
func (f Function4) GetReturn() pgtypes.DoltgresType
GetReturn implements the FunctionInterface interface.
func (Function4) NonDeterministic ¶ added in v0.11.0
NonDeterministic implements the FunctionInterface interface.
func (Function4) VariadicIndex ¶ added in v0.11.0
VariadicIndex implements the FunctionInterface interface.
type FunctionInterface ¶
type FunctionInterface interface { // GetName returns the name of the function. The name is case-insensitive, so the casing does not matter. GetName() string // GetReturn returns the return type. GetReturn() pgtypes.DoltgresType // GetParameters returns the parameter types for the function. GetParameters() []pgtypes.DoltgresType // VariadicIndex returns the index of the variadic parameter, if it exists, or -1 otherwise VariadicIndex() int // GetExpectedParameterCount returns the number of parameters that are valid for this function. GetExpectedParameterCount() int // NonDeterministic returns whether the function is non-deterministic. NonDeterministic() bool // IsStrict returns whether the function is STRICT, which means if any parameter is NULL, then it returns NULL. // Otherwise, if it's not, the NULL input must be handled by user. IsStrict() bool // contains filtered or unexported methods }
FunctionInterface is an interface for PostgreSQL functions.
type IntermediateFunction ¶
IntermediateFunction is an expression that represents an incomplete PostgreSQL function.
func GetBinaryFunction ¶
func GetBinaryFunction(operator Operator) IntermediateFunction
GetBinaryFunction returns the binary function that matches the given operator.
func GetUnaryFunction ¶
func GetUnaryFunction(operator Operator) IntermediateFunction
GetUnaryFunction returns the unary function that matches the given operator.
func (IntermediateFunction) Compile ¶
func (f IntermediateFunction) Compile(name string, parameters ...sql.Expression) *CompiledFunction
Compile returns a CompiledFunction created from the calling IntermediateFunction. Returns a nil function if it could not be compiled.
type LiteralInterface ¶
type LiteralInterface interface { sql.Expression GetDoltgresType() pgtypes.DoltgresType ConformsToLiteralInterface() }
LiteralInterface is used to prevent import cycles, since we can't reference pgexprs.Literal from this package.
type Operator ¶
type Operator byte
Operator is a unary or binary operator.
const ( Operator_BinaryPlus Operator = iota // + Operator_BinaryMinus // - Operator_BinaryMultiply // * Operator_BinaryDivide // / Operator_BinaryMod // % Operator_BinaryShiftLeft // << Operator_BinaryShiftRight // >> Operator_BinaryLessThan // < Operator_BinaryGreaterThan // > Operator_BinaryLessOrEqual // <= Operator_BinaryGreaterOrEqual // >= Operator_BinaryEqual // = Operator_BinaryNotEqual // <> or != (they're equivalent in all cases) Operator_BinaryBitAnd // & Operator_BinaryBitOr // | Operator_BinaryBitXor // ^ Operator_BinaryConcatenate // || Operator_BinaryJSONExtractJson // -> Operator_BinaryJSONExtractText // ->> Operator_BinaryJSONExtractPathJson // #> Operator_BinaryJSONExtractPathText // #>> Operator_BinaryJSONContainsRight // @> Operator_BinaryJSONContainsLeft // <@ Operator_BinaryJSONTopLevel // ? Operator_BinaryJSONTopLevelAny // ?| Operator_BinaryJSONTopLevelAll // ?& Operator_UnaryPlus // + Operator_UnaryMinus // - )
func GetOperatorFromString ¶ added in v0.11.0
GetOperatorFromString returns the binary operator for the given subOperator.
type Overload ¶ added in v0.11.0
type Overload struct {
// contains filtered or unexported fields
}
Overload is a single overload of a given function, used during evaluation to match the arguments provided to a particular overload.
type Overloads ¶ added in v0.11.0
type Overloads struct { // ByParamType contains all overloads for the function with this name, indexed by the key of the parameter types. ByParamType map[string]FunctionInterface // AllOverloads contains all overloads for the function with this name AllOverloads []FunctionInterface }
Overloads is the collection of all overloads for a given function name.
func NewOverloads ¶ added in v0.11.0
func NewOverloads() *Overloads
NewOverloads creates a new empty overload collection.
func (*Overloads) Add ¶ added in v0.11.0
func (o *Overloads) Add(function FunctionInterface) error
Add adds the given function to the overload collection. Returns an error if the there's a problem with the function's declaration.
func (*Overloads) ExactMatchForBaseIds ¶ added in v0.11.0
func (o *Overloads) ExactMatchForBaseIds(types ...pgtypes.DoltgresTypeBaseID) (FunctionInterface, bool)
ExactMatchForBaseIds returns the function that exactly matches the given parameter types, or nil if no overload with those types exists.
func (*Overloads) ExactMatchForTypes ¶ added in v0.11.0
func (o *Overloads) ExactMatchForTypes(types []pgtypes.DoltgresType) (FunctionInterface, bool)
ExactMatchForTypes returns the function that exactly matches the given parameter types, or nil if no overload with those types exists.
type TypeCast ¶
type TypeCast struct { FromType pgtypes.DoltgresType ToType pgtypes.DoltgresType Function TypeCastFunction }
TypeCast is used to cast from one type to another.
type TypeCastFunction ¶
TypeCastFunction is a function that takes a value of a particular kind of type, and returns it as another kind of type. The targetType given should match the "To" type used to obtain the cast.
func GetAssignmentCast ¶ added in v0.8.0
func GetAssignmentCast(fromType pgtypes.DoltgresTypeBaseID, toType pgtypes.DoltgresTypeBaseID) TypeCastFunction
GetAssignmentCast returns the assignment type cast function that will cast the "from" type to the "to" type. Returns nil if such a cast is not valid.
func GetExplicitCast ¶ added in v0.6.0
func GetExplicitCast(fromType pgtypes.DoltgresTypeBaseID, toType pgtypes.DoltgresTypeBaseID) TypeCastFunction
GetExplicitCast returns the explicit type cast function that will cast the "from" type to the "to" type. Returns nil if such a cast is not valid.
func GetImplicitCast ¶ added in v0.6.0
func GetImplicitCast(fromType pgtypes.DoltgresTypeBaseID, toType pgtypes.DoltgresTypeBaseID) TypeCastFunction
GetImplicitCast returns the implicit type cast function that will cast the "from" type to the "to" type. Returns nil if such a cast is not valid.