2019-06-21 13:56:57 +02:00
|
|
|
package jet
|
2019-03-30 10:05:30 +01:00
|
|
|
|
2019-05-06 12:42:15 +02:00
|
|
|
import "errors"
|
|
|
|
|
|
2019-05-05 18:03:30 +02:00
|
|
|
type funcExpressionImpl struct {
|
2019-04-03 11:03:07 +02:00
|
|
|
expressionInterfaceImpl
|
|
|
|
|
|
2019-06-01 15:00:37 +02:00
|
|
|
name string
|
2019-06-04 12:10:23 +02:00
|
|
|
expressions []Expression
|
2019-06-03 14:41:39 +02:00
|
|
|
noBrackets bool
|
2019-05-05 18:03:30 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newFunc(name string, expressions []Expression, parent Expression) *funcExpressionImpl {
|
2019-05-05 18:03:30 +02:00
|
|
|
funcExp := &funcExpressionImpl{
|
2019-06-01 15:00:37 +02:00
|
|
|
name: name,
|
|
|
|
|
expressions: expressions,
|
2019-04-03 11:03:07 +02:00
|
|
|
}
|
2019-03-30 10:05:30 +01:00
|
|
|
|
2019-05-05 18:03:30 +02:00
|
|
|
if parent != nil {
|
|
|
|
|
funcExp.expressionInterfaceImpl.parent = parent
|
|
|
|
|
} else {
|
|
|
|
|
funcExp.expressionInterfaceImpl.parent = funcExp
|
|
|
|
|
}
|
2019-03-30 10:05:30 +01:00
|
|
|
|
2019-05-05 18:03:30 +02:00
|
|
|
return funcExp
|
2019-03-30 10:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-07-08 10:48:03 +02:00
|
|
|
func (f *funcExpressionImpl) serialize(statement statementType, out *sqlBuilder, options ...serializeOption) error {
|
2019-05-13 12:33:11 +02:00
|
|
|
if f == nil {
|
2019-06-01 15:00:37 +02:00
|
|
|
return errors.New("Function expressions is nil. ")
|
2019-05-13 12:33:11 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-03 14:41:39 +02:00
|
|
|
addBrackets := !f.noBrackets || len(f.expressions) > 0
|
|
|
|
|
|
|
|
|
|
if addBrackets {
|
|
|
|
|
out.writeString(f.name + "(")
|
|
|
|
|
} else {
|
|
|
|
|
out.writeString(f.name)
|
|
|
|
|
}
|
2019-05-12 18:15:23 +02:00
|
|
|
|
2019-06-01 15:00:37 +02:00
|
|
|
err := serializeExpressionList(statement, f.expressions, ", ", out)
|
2019-03-30 10:05:30 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2019-06-03 14:41:39 +02:00
|
|
|
|
|
|
|
|
if addBrackets {
|
|
|
|
|
out.writeString(")")
|
|
|
|
|
}
|
2019-03-30 10:05:30 +01:00
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 14:41:39 +02:00
|
|
|
type boolFunc struct {
|
|
|
|
|
funcExpressionImpl
|
|
|
|
|
boolInterfaceImpl
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newBoolFunc(name string, expressions ...Expression) BoolExpression {
|
2019-06-03 14:41:39 +02:00
|
|
|
boolFunc := &boolFunc{}
|
|
|
|
|
|
|
|
|
|
boolFunc.funcExpressionImpl = *newFunc(name, expressions, boolFunc)
|
|
|
|
|
boolFunc.boolInterfaceImpl.parent = boolFunc
|
|
|
|
|
|
|
|
|
|
return boolFunc
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
type floatFunc struct {
|
2019-05-05 18:03:30 +02:00
|
|
|
funcExpressionImpl
|
2019-05-31 12:59:57 +02:00
|
|
|
floatInterfaceImpl
|
2019-05-05 18:03:30 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newFloatFunc(name string, expressions ...Expression) FloatExpression {
|
2019-05-31 12:59:57 +02:00
|
|
|
floatFunc := &floatFunc{}
|
2019-05-05 18:03:30 +02:00
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
floatFunc.funcExpressionImpl = *newFunc(name, expressions, floatFunc)
|
|
|
|
|
floatFunc.floatInterfaceImpl.parent = floatFunc
|
2019-05-05 18:03:30 +02:00
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
return floatFunc
|
2019-05-20 17:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
type integerFunc struct {
|
|
|
|
|
funcExpressionImpl
|
|
|
|
|
integerInterfaceImpl
|
2019-05-06 12:42:15 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newIntegerFunc(name string, expressions ...Expression) IntegerExpression {
|
2019-05-31 12:59:57 +02:00
|
|
|
floatFunc := &integerFunc{}
|
2019-05-06 12:42:15 +02:00
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
floatFunc.funcExpressionImpl = *newFunc(name, expressions, floatFunc)
|
|
|
|
|
floatFunc.integerInterfaceImpl.parent = floatFunc
|
2019-05-06 12:42:15 +02:00
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
return floatFunc
|
2019-05-06 12:42:15 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-02 12:45:46 +02:00
|
|
|
type stringFunc struct {
|
|
|
|
|
funcExpressionImpl
|
|
|
|
|
stringInterfaceImpl
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newStringFunc(name string, expressions ...Expression) StringExpression {
|
2019-06-02 12:45:46 +02:00
|
|
|
stringFunc := &stringFunc{}
|
|
|
|
|
|
|
|
|
|
stringFunc.funcExpressionImpl = *newFunc(name, expressions, stringFunc)
|
|
|
|
|
stringFunc.stringInterfaceImpl.parent = stringFunc
|
|
|
|
|
|
|
|
|
|
return stringFunc
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-02 16:22:22 +02:00
|
|
|
type dateFunc struct {
|
|
|
|
|
funcExpressionImpl
|
|
|
|
|
dateInterfaceImpl
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newDateFunc(name string, expressions ...Expression) *dateFunc {
|
2019-06-02 16:22:22 +02:00
|
|
|
dateFunc := &dateFunc{}
|
|
|
|
|
|
|
|
|
|
dateFunc.funcExpressionImpl = *newFunc(name, expressions, dateFunc)
|
|
|
|
|
dateFunc.dateInterfaceImpl.parent = dateFunc
|
|
|
|
|
|
|
|
|
|
return dateFunc
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 14:41:39 +02:00
|
|
|
type timeFunc struct {
|
2019-06-02 12:45:46 +02:00
|
|
|
funcExpressionImpl
|
2019-06-03 14:41:39 +02:00
|
|
|
timeInterfaceImpl
|
2019-06-02 12:45:46 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newTimeFunc(name string, expressions ...Expression) *timeFunc {
|
2019-06-03 14:41:39 +02:00
|
|
|
timeFun := &timeFunc{}
|
2019-06-02 12:45:46 +02:00
|
|
|
|
2019-06-03 14:41:39 +02:00
|
|
|
timeFun.funcExpressionImpl = *newFunc(name, expressions, timeFun)
|
|
|
|
|
timeFun.timeInterfaceImpl.parent = timeFun
|
2019-06-02 12:45:46 +02:00
|
|
|
|
2019-06-03 14:41:39 +02:00
|
|
|
return timeFun
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type timezFunc struct {
|
|
|
|
|
funcExpressionImpl
|
|
|
|
|
timezInterfaceImpl
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newTimezFunc(name string, expressions ...Expression) *timezFunc {
|
2019-06-03 14:41:39 +02:00
|
|
|
timezFun := &timezFunc{}
|
|
|
|
|
|
|
|
|
|
timezFun.funcExpressionImpl = *newFunc(name, expressions, timezFun)
|
|
|
|
|
timezFun.timezInterfaceImpl.parent = timezFun
|
|
|
|
|
|
|
|
|
|
return timezFun
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type timestampFunc struct {
|
|
|
|
|
funcExpressionImpl
|
|
|
|
|
timestampInterfaceImpl
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newTimestampFunc(name string, expressions ...Expression) *timestampFunc {
|
2019-06-03 14:41:39 +02:00
|
|
|
timestampFunc := ×tampFunc{}
|
|
|
|
|
|
|
|
|
|
timestampFunc.funcExpressionImpl = *newFunc(name, expressions, timestampFunc)
|
|
|
|
|
timestampFunc.timestampInterfaceImpl.parent = timestampFunc
|
|
|
|
|
|
|
|
|
|
return timestampFunc
|
2019-06-02 12:45:46 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-02 16:22:22 +02:00
|
|
|
type timestampzFunc struct {
|
|
|
|
|
funcExpressionImpl
|
|
|
|
|
timestampzInterfaceImpl
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newTimestampzFunc(name string, expressions ...Expression) *timestampzFunc {
|
2019-06-02 16:22:22 +02:00
|
|
|
timestampzFunc := ×tampzFunc{}
|
|
|
|
|
|
|
|
|
|
timestampzFunc.funcExpressionImpl = *newFunc(name, expressions, timestampzFunc)
|
|
|
|
|
timestampzFunc.timestampzInterfaceImpl.parent = timestampzFunc
|
|
|
|
|
|
|
|
|
|
return timestampzFunc
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func ROW(expressions ...Expression) Expression {
|
2019-06-04 11:52:37 +02:00
|
|
|
return newFunc("ROW", expressions, nil)
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-01 15:00:37 +02:00
|
|
|
// ------------------ Mathematical functions ---------------//
|
|
|
|
|
|
|
|
|
|
func ABSf(floatExpression FloatExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("ABS", floatExpression)
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-21 12:30:32 +02:00
|
|
|
func ABSi(integerExpression IntegerExpression) IntegerExpression {
|
|
|
|
|
return newIntegerFunc("ABS", integerExpression)
|
2019-06-01 15:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-21 12:30:32 +02:00
|
|
|
func SQRT(numericExpression NumericExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("SQRT", numericExpression)
|
2019-06-01 15:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-21 12:30:32 +02:00
|
|
|
func CBRT(numericExpression NumericExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("CBRT", numericExpression)
|
2019-06-01 15:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CEIL(floatExpression FloatExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("CEIL", floatExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func FLOOR(floatExpression FloatExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("FLOOR", floatExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ROUND(floatExpression FloatExpression, intExpression ...IntegerExpression) FloatExpression {
|
|
|
|
|
if len(intExpression) > 0 {
|
|
|
|
|
return newFloatFunc("ROUND", floatExpression, intExpression[0])
|
|
|
|
|
}
|
|
|
|
|
return newFloatFunc("ROUND", floatExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SIGN(floatExpression FloatExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("SIGN", floatExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TRUNC(floatExpression FloatExpression, intExpression ...IntegerExpression) FloatExpression {
|
|
|
|
|
if len(intExpression) > 0 {
|
|
|
|
|
return newFloatFunc("TRUNC", floatExpression, intExpression[0])
|
|
|
|
|
}
|
|
|
|
|
return newFloatFunc("TRUNC", floatExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LN(floatExpression FloatExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("LN", floatExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LOG(floatExpression FloatExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("LOG", floatExpression)
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 18:28:16 +02:00
|
|
|
// ----------------- Aggregate functions -------------------//
|
|
|
|
|
|
2019-06-21 12:30:32 +02:00
|
|
|
func AVG(numericExpression NumericExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("AVG", numericExpression)
|
2019-06-03 18:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BIT_AND(integerExpression IntegerExpression) IntegerExpression {
|
|
|
|
|
return newIntegerFunc("BIT_AND", integerExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BIT_OR(integerExpression IntegerExpression) IntegerExpression {
|
|
|
|
|
return newIntegerFunc("BIT_OR", integerExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BOOL_AND(boolExpression BoolExpression) BoolExpression {
|
|
|
|
|
return newBoolFunc("BOOL_AND", boolExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BOOL_OR(boolExpression BoolExpression) BoolExpression {
|
|
|
|
|
return newBoolFunc("BOOL_OR", boolExpression)
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func COUNT(expression Expression) IntegerExpression {
|
2019-06-03 18:28:16 +02:00
|
|
|
return newIntegerFunc("COUNT", expression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func EVERY(boolExpression BoolExpression) BoolExpression {
|
|
|
|
|
return newBoolFunc("EVERY", boolExpression)
|
|
|
|
|
}
|
2019-06-01 15:00:37 +02:00
|
|
|
|
|
|
|
|
func MAXf(floatExpression FloatExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("MAX", floatExpression)
|
2019-05-06 12:42:15 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
func MAXi(integerExpression IntegerExpression) IntegerExpression {
|
|
|
|
|
return newIntegerFunc("MAX", integerExpression)
|
2019-05-06 12:42:15 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-03 18:28:16 +02:00
|
|
|
func MINf(floatExpression FloatExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("MIN", floatExpression)
|
2019-06-01 15:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-03 18:28:16 +02:00
|
|
|
func MINi(integerExpression IntegerExpression) IntegerExpression {
|
|
|
|
|
return newIntegerFunc("MIN", integerExpression)
|
2019-05-06 12:42:15 +02:00
|
|
|
}
|
2019-06-01 15:00:37 +02:00
|
|
|
|
2019-06-03 18:28:16 +02:00
|
|
|
func SUMf(floatExpression FloatExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("SUM", floatExpression)
|
2019-06-01 15:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-03 18:28:16 +02:00
|
|
|
func SUMi(integerExpression IntegerExpression) IntegerExpression {
|
|
|
|
|
return newIntegerFunc("SUM", integerExpression)
|
2019-06-01 15:00:37 +02:00
|
|
|
}
|
2019-06-02 12:45:46 +02:00
|
|
|
|
|
|
|
|
//------------ String functions ------------------//
|
|
|
|
|
|
|
|
|
|
func BIT_LENGTH(stringExpression StringExpression) IntegerExpression {
|
|
|
|
|
return newIntegerFunc("BIT_LENGTH", stringExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CHAR_LENGTH(stringExpression StringExpression) IntegerExpression {
|
|
|
|
|
return newIntegerFunc("CHAR_LENGTH", stringExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func OCTET_LENGTH(stringExpression StringExpression) IntegerExpression {
|
|
|
|
|
return newIntegerFunc("OCTET_LENGTH", stringExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LOWER(stringExpression StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("LOWER", stringExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func UPPER(stringExpression StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("UPPER", stringExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BTRIM(stringExpression StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("BTRIM", stringExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LTRIM(str StringExpression, trimChars ...StringExpression) StringExpression {
|
|
|
|
|
if len(trimChars) > 0 {
|
|
|
|
|
return newStringFunc("LTRIM", str, trimChars[0])
|
|
|
|
|
}
|
|
|
|
|
return newStringFunc("LTRIM", str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RTRIM(str StringExpression, trimChars ...StringExpression) StringExpression {
|
|
|
|
|
if len(trimChars) > 0 {
|
|
|
|
|
return newStringFunc("RTRIM", str, trimChars[0])
|
|
|
|
|
}
|
|
|
|
|
return newStringFunc("RTRIM", str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CHR(integerExpression IntegerExpression) StringExpression {
|
|
|
|
|
return newStringFunc("CHR", integerExpression)
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 14:41:39 +02:00
|
|
|
//
|
2019-06-04 12:10:23 +02:00
|
|
|
//func CONCAT(expressions ...Expression) StringExpression {
|
2019-06-02 12:45:46 +02:00
|
|
|
// return newStringFunc("CONCAT", expressions...)
|
|
|
|
|
//}
|
|
|
|
|
//
|
2019-06-04 12:10:23 +02:00
|
|
|
//func CONCAT_WS(expressions ...Expression) StringExpression {
|
2019-06-02 12:45:46 +02:00
|
|
|
// return newStringFunc("CONCAT_WS", expressions...)
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
func CONVERT(str StringExpression, fromEncoding StringExpression, toEncoding StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("CONVERT", str, fromEncoding, toEncoding)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CONVERT_FROM(str StringExpression, fromEncoding StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("CONVERT_FROM", str, fromEncoding)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CONVERT_TO(str StringExpression, toEncoding StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("CONVERT_TO", str, toEncoding)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ENCODE(data StringExpression, format StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("ENCODE", data, format)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DECODE(data StringExpression, format StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("DECODE", data, format)
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 11:52:37 +02:00
|
|
|
//func FORMAT(formatStr StringExpression, formatArgs ...expressions) StringExpression {
|
|
|
|
|
// args := []expressions{formatStr}
|
2019-06-02 12:45:46 +02:00
|
|
|
// args = append(args, formatArgs...)
|
|
|
|
|
// return newStringFunc("FORMAT", args...)
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
func INITCAP(str StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("INITCAP", str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LEFT(str StringExpression, n IntegerExpression) StringExpression {
|
|
|
|
|
return newStringFunc("LEFT", str, n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RIGHT(str StringExpression, n IntegerExpression) StringExpression {
|
|
|
|
|
return newStringFunc("RIGHT", str, n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LENGTH(str StringExpression, encoding ...StringExpression) StringExpression {
|
|
|
|
|
if len(encoding) > 0 {
|
|
|
|
|
return newStringFunc("LENGTH", str, encoding[0])
|
|
|
|
|
}
|
|
|
|
|
return newStringFunc("LENGTH", str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LPAD(str StringExpression, length IntegerExpression, text ...StringExpression) StringExpression {
|
|
|
|
|
if len(text) > 0 {
|
|
|
|
|
return newStringFunc("LPAD", str, length, text[0])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newStringFunc("LPAD", str, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RPAD(str StringExpression, length IntegerExpression, text ...StringExpression) StringExpression {
|
|
|
|
|
if len(text) > 0 {
|
|
|
|
|
return newStringFunc("RPAD", str, length, text[0])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newStringFunc("RPAD", str, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func MD5(stringExpression StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("MD5", stringExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func REPEAT(str StringExpression, n IntegerExpression) StringExpression {
|
|
|
|
|
return newStringFunc("REPEAT", str, n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func REPLACE(text, from, to StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("REPLACE", text, from, to)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func REVERSE(stringExpression StringExpression) StringExpression {
|
|
|
|
|
return newStringFunc("REVERSE", stringExpression)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func STRPOS(str, substring StringExpression) IntegerExpression {
|
|
|
|
|
return newIntegerFunc("STRPOS", str, substring)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SUBSTR(str StringExpression, from IntegerExpression, count ...IntegerExpression) StringExpression {
|
|
|
|
|
if len(count) > 0 {
|
|
|
|
|
return newStringFunc("SUBSTR", str, from, count[0])
|
|
|
|
|
}
|
|
|
|
|
return newStringFunc("SUBSTR", str, from)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TO_ASCII(str StringExpression, encoding ...StringExpression) StringExpression {
|
|
|
|
|
if len(encoding) > 0 {
|
|
|
|
|
return newStringFunc("TO_ASCII", str, encoding[0])
|
|
|
|
|
}
|
|
|
|
|
return newStringFunc("TO_ASCII", str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TO_HEX(number IntegerExpression) StringExpression {
|
|
|
|
|
return newStringFunc("TO_HEX", number)
|
|
|
|
|
}
|
2019-06-02 16:22:22 +02:00
|
|
|
|
|
|
|
|
//----------Data Type Formatting Functions ----------------------//
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func TO_CHAR(expression Expression, text StringExpression) StringExpression {
|
2019-06-02 16:22:22 +02:00
|
|
|
return newStringFunc("TO_CHAR", expression, text)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TO_DATE(dateStr, format StringExpression) DateExpression {
|
|
|
|
|
return newDateFunc("TO_DATE", dateStr, format)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TO_NUMBER(floatStr, format StringExpression) FloatExpression {
|
|
|
|
|
return newFloatFunc("TO_NUMBER", floatStr, format)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TO_TIMESTAMP(timestampzStr, format StringExpression) TimestampzExpression {
|
|
|
|
|
return newTimestampzFunc("TO_TIMESTAMP", timestampzStr, format)
|
|
|
|
|
}
|
2019-06-03 14:41:39 +02:00
|
|
|
|
|
|
|
|
//----------------- Date/Time Functions and Operators ---------------//
|
|
|
|
|
|
|
|
|
|
func CURRENT_DATE() DateExpression {
|
|
|
|
|
dateFunc := newDateFunc("CURRENT_DATE")
|
|
|
|
|
dateFunc.noBrackets = true
|
|
|
|
|
return dateFunc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CURRENT_TIME(precision ...int) TimezExpression {
|
|
|
|
|
var timezFunc *timezFunc
|
|
|
|
|
|
|
|
|
|
if len(precision) > 0 {
|
2019-06-04 11:52:37 +02:00
|
|
|
timezFunc = newTimezFunc("CURRENT_TIME", constLiteral(precision[0]))
|
2019-06-03 14:41:39 +02:00
|
|
|
} else {
|
|
|
|
|
timezFunc = newTimezFunc("CURRENT_TIME")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timezFunc.noBrackets = true
|
|
|
|
|
|
|
|
|
|
return timezFunc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CURRENT_TIMESTAMP(precision ...int) TimestampzExpression {
|
|
|
|
|
var timestampzFunc *timestampzFunc
|
|
|
|
|
|
|
|
|
|
if len(precision) > 0 {
|
2019-06-04 11:52:37 +02:00
|
|
|
timestampzFunc = newTimestampzFunc("CURRENT_TIMESTAMP", constLiteral(precision[0]))
|
2019-06-03 14:41:39 +02:00
|
|
|
} else {
|
|
|
|
|
timestampzFunc = newTimestampzFunc("CURRENT_TIMESTAMP")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timestampzFunc.noBrackets = true
|
|
|
|
|
|
|
|
|
|
return timestampzFunc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LOCALTIME(precision ...int) TimeExpression {
|
|
|
|
|
var timeFunc *timeFunc
|
|
|
|
|
|
|
|
|
|
if len(precision) > 0 {
|
2019-06-04 11:52:37 +02:00
|
|
|
timeFunc = newTimeFunc("LOCALTIME", constLiteral(precision[0]))
|
2019-06-03 14:41:39 +02:00
|
|
|
} else {
|
|
|
|
|
timeFunc = newTimeFunc("LOCALTIME")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timeFunc.noBrackets = true
|
|
|
|
|
|
|
|
|
|
return timeFunc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LOCALTIMESTAMP(precision ...int) TimestampExpression {
|
|
|
|
|
var timestampFunc *timestampFunc
|
|
|
|
|
|
|
|
|
|
if len(precision) > 0 {
|
2019-06-04 11:52:37 +02:00
|
|
|
timestampFunc = newTimestampFunc("LOCALTIMESTAMP", constLiteral(precision[0]))
|
2019-06-03 14:41:39 +02:00
|
|
|
} else {
|
|
|
|
|
timestampFunc = newTimestampFunc("LOCALTIMESTAMP")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timestampFunc.noBrackets = true
|
|
|
|
|
|
|
|
|
|
return timestampFunc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NOW() TimestampzExpression {
|
|
|
|
|
return newTimestampzFunc("NOW")
|
|
|
|
|
}
|
2019-06-03 17:38:47 +02:00
|
|
|
|
|
|
|
|
// --------------- Conditional Expressions Functions -------------//
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func COALESCE(value Expression, values ...Expression) Expression {
|
|
|
|
|
var allValues = []Expression{value}
|
2019-06-03 17:38:47 +02:00
|
|
|
allValues = append(allValues, values...)
|
|
|
|
|
return newFunc("COALESCE", allValues, nil)
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func NULLIF(value1, value2 Expression) Expression {
|
|
|
|
|
return newFunc("NULLIF", []Expression{value1, value2}, nil)
|
2019-06-03 17:38:47 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func GREATEST(value Expression, values ...Expression) Expression {
|
|
|
|
|
var allValues = []Expression{value}
|
2019-06-03 17:38:47 +02:00
|
|
|
allValues = append(allValues, values...)
|
|
|
|
|
return newFunc("GREATEST", allValues, nil)
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func LEAST(value Expression, values ...Expression) Expression {
|
|
|
|
|
var allValues = []Expression{value}
|
2019-06-03 17:38:47 +02:00
|
|
|
allValues = append(allValues, values...)
|
|
|
|
|
return newFunc("LEAST", allValues, nil)
|
|
|
|
|
}
|