functions

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Catalog = []Function{
	abs,
	acos,
	acosd,
	acosh,
	ascii,
	asin,
	asind,
	asinh,
	atan,
	atan2,
	atan2d,
	atand,
	atanh,
	bit_length,
	btrim,
	cbrt,
	ceil,
	ceiling,
	char_length,
	character_length,
	chr,
	cos,
	cosd,
	cosh,
	cot,
	cotd,
	degrees,
	div,
	exp,
	factorial,
	floor,
	gcd,
	initcap,
	lcm,
	left,
	length,
	ln,
	log,
	log10,
	lower,
	lpad,
	ltrim,
	md5,
	min_scale,
	mod,
	octet_length,
	pi,
	power,
	radians,
	random,
	repeat,
	replace,
	reverse,
	right,
	round,
	rpad,
	rtrim,
	scale,
	sign,
	sin,
	sind,
	sinh,
	split_part,
	sqrt,
	strpos,
	substr,
	tan,
	tand,
	tanh,
	to_hex,
	trim_scale,
	trunc,
	upper,
	width_bucket,
}

Catalog contains all of the PostgreSQL functions. If a new function is added, make sure to add it to the catalog here.

Functions

This section is empty.

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) Eval

func (c *CompiledFunction) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)

Eval 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 []IntermediateParameter) 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 FloatType

type FloatType struct {
	Value        float64
	IsNull       bool
	OriginalType ParameterType
	Source       Source
}

FloatType is a floating point type (float32 is upcast to float64).

type Function

type Function struct {
	Name      string
	Overloads []any
}

Function is a name, along with a collection of functions, that represent a single PostgreSQL function with all of its overloads.

type IntegerType

type IntegerType struct {
	Value        int64
	IsNull       bool
	OriginalType ParameterType
	Source       Source
}

IntegerType is an integer type (all integer types are upcast to int64).

type IntermediateParameter

type IntermediateParameter struct {
	Value        interface{}
	IsNull       bool
	OriginalType ParameterType
	CurrentType  ParameterType
	Source       Source
}

IntermediateParameter is a parameter before it has been finalized.

func (IntermediateParameter) ToValue

func (ip IntermediateParameter) ToValue() reflect.Value

ToValue converts the intermediate parameter into a concrete parameter type (IntegerType, FloatType, etc.) and returns it as a reflect.Value, which may be passed to the matched function.

type NumericType

type NumericType struct {
	Value        float64 //TODO: should be decimal, but our engine support isn't quite there yet
	IsNull       bool
	OriginalType ParameterType
	Source       Source
}

NumericType is a decimal type (all integer and float types are upcast to decimal).

type OverloadDeduction

type OverloadDeduction struct {
	Function      reflect.Value
	ReturnSqlType sql.Type
	ReturnValType ParameterType
	Parameter     [ParameterType_Length]*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 []IntermediateParameter) (*OverloadDeduction, error)

Resolve returns an overload that either matches the given parameters exactly, or is a viable match after casting. This will modify the parameter slice in-place. Returns a nil OverloadDeduction if a viable match is not found.

func (*OverloadDeduction) ResolveByType

func (overload *OverloadDeduction) ResolveByType(originalTypes []ParameterType) (*OverloadDeduction, []ParameterType)

ResolveByType returns the best matching overload for the given types. The returned types represent the actual types used by the overload, which may differ from the calling types. It is up to the caller to cast the parameters to match the types expected by the returned overload. Returns a nil OverloadDeduction if a viable match is not found.

type ParameterType

type ParameterType uint8

ParameterType represents the type of a parameter.

const (
	ParameterType_Null      ParameterType = iota // The parameter is a NULL value, and is therefore typeless
	ParameterType_Integer                        // The parameter is an IntegerType type
	ParameterType_Float                          // The parameter is a FloatType type
	ParameterType_Numeric                        // The parameter is a NumericType type
	ParameterType_String                         // The parameter is a StringType type
	ParameterType_Timestamp                      // The parameter is a TimestampType type

	ParameterType_Length // The number of parameters. This should always be last in the enum declaration.
)

func ParameterTypeFromReflection

func ParameterTypeFromReflection(t reflect.Type) (ParameterType, sql.Type, bool)

ParameterTypeFromReflection returns the ParameterType and equivalent sql.Type from the given reflection type. If the given type does not match a ParameterType, then this returns false.

func (ParameterType) PotentialCasts

func (pt ParameterType) PotentialCasts() []ParameterType

PotentialCasts returns all potential casts for the current type. For example, an IntegerType may be cast to a FloatType. Casts may be bidirectional, as a StringType may cast to an IntegerType, and an IntegerType may cast to a StringType.

func (ParameterType) String

func (pt ParameterType) String() string

PotentialCasts returns all potential casts for the current type. For example, an IntegerType may be cast to a FloatType. Casts may be bidirectional, as a StringType may cast to an IntegerType, and an IntegerType may cast to a StringType.

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.

const (
	Source_Expression Source = iota // The source is some expression. This may change as more sources are added.
	Source_Constant                 // The source is a constant value
	Source_Column                   // The source is a column
)

type StringType

type StringType struct {
	Value        string
	IsNull       bool
	OriginalType ParameterType
	Source       Source
}

StringType is a string type.

type TimestampType

type TimestampType struct {
	Value        time.Time
	IsNull       bool
	OriginalType ParameterType
	Source       Source
}

TimestampType is a timestamp type.

Jump to

Keyboard shortcuts

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