Documentation
¶
Index ¶
- Variables
- func AddExplicitTypeCast(cast TypeCast) error
- func AddImplicitTypeCast(cast TypeCast) error
- func GetPotentialExplicitCasts(fromType pgtypes.DoltgresTypeBaseID) []pgtypes.DoltgresType
- func GetPotentialImplicitCasts(fromType pgtypes.DoltgresTypeBaseID) []pgtypes.DoltgresType
- func Initialize()
- func MustAddExplicitTypeCast(cast TypeCast)
- func MustAddImplicitTypeCast(cast TypeCast)
- func RegisterBinaryFunction(operator Operator, f Function2)
- func RegisterFunction(f FunctionInterface)
- func RegisterUnaryFunction(operator Operator, f Function1)
- 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) IsNullable() bool
- func (c *CompiledFunction) OverloadString(types []pgtypes.DoltgresType) string
- func (c *CompiledFunction) Resolved() bool
- func (c *CompiledFunction) String() string
- func (c *CompiledFunction) Type() sql.Type
- func (c *CompiledFunction) WithChildren(children ...sql.Expression) (sql.Expression, error)
- type Context
- type Function
- type Function0
- type Function1
- type Function2
- type Function3
- type Function4
- type FunctionInterface
- type IntermediateFunction
- type LiteralInterface
- type Operator
- type OverloadDeduction
- type Source
- type TypeCast
- type TypeCastFunction
Constants ¶
This section is empty.
Variables ¶
var Catalog = map[string][]FunctionInterface{}
Catalog contains all of the PostgreSQL functions.
Functions ¶
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 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 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().
Types ¶
type CompiledFunction ¶
type CompiledFunction struct { Name string Parameters []sql.Expression Functions *OverloadDeduction }
CompiledFunction is an expression that represents a fully-analyzed PostgreSQL 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) 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) 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 Function ¶
Function is a name, along with a collection of functions, that represent a single PostgreSQL function with all of its overloads.
type Function0 ¶
type Function0 struct { Name string Return pgtypes.DoltgresType Parameters []pgtypes.DoltgresType Callable func(ctx 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.
type Function1 ¶
type Function1 struct { Name string Return pgtypes.DoltgresType Parameters []pgtypes.DoltgresType Callable func(ctx Context, val1 any) (any, error) }
Function1 is a function that takes one parameter.
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.
type Function2 ¶
type Function2 struct { Name string Return pgtypes.DoltgresType Parameters []pgtypes.DoltgresType Callable func(ctx Context, val1 any, val2 any) (any, error) }
Function2 is a function that takes two parameters.
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.
type Function3 ¶
type Function3 struct { Name string Return pgtypes.DoltgresType Parameters []pgtypes.DoltgresType Callable func(ctx Context, val1 any, val2 any, val3 any) (any, error) }
Function3 is a function that takes three parameters.
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.
type Function4 ¶
type Function4 struct { Name string Return pgtypes.DoltgresType Parameters []pgtypes.DoltgresType Callable func(ctx Context, val1 any, val2 any, val3 any, val4 any) (any, error) }
Function4 is a function that takes four parameters.
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.
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 // GetExpectedParameterCount returns the number of paramters that are valid for this function. GetExpectedParameterCount() int // contains filtered or unexported methods }
FunctionInterface is an interface for PostgreSQL functions.
type IntermediateFunction ¶
type IntermediateFunction struct {
Functions *OverloadDeduction
}
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.
type OverloadDeduction ¶
type OverloadDeduction struct { Function FunctionInterface Parameter map[pgtypes.DoltgresTypeBaseID]*OverloadDeduction }
OverloadDeduction handles resolving which function to call by iterating over the parameter expressions. This also handles casting between types if an exact function match is not found.
func (*OverloadDeduction) Resolve ¶
func (overload *OverloadDeduction) Resolve(parameters []pgtypes.DoltgresType, sources []Source) (*OverloadDeduction, []TypeCastFunction, error)
Resolve returns an overload that either matches the given parameters exactly, or is a viable match after casting. Returns a nil OverloadDeduction if a viable match is not found.
type Source ¶
type Source uint8
Source defines what kind of expression generated the given value, as some functions are context-dependent, and we need to approximate the context.
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 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.