Expression casting between builtin types.

This commit is contained in:
zer0sub 2019-06-02 18:12:44 +02:00
parent fcd3596780
commit 37a55e6ee3
8 changed files with 294 additions and 47 deletions

View file

@ -21,6 +21,16 @@ type expression interface {
ASC() orderByClause
DESC() orderByClause
CAST_TO_BOOL() BoolExpression
CAST_TO_INTEGER() IntegerExpression
CAST_TO_DOUBLE() FloatExpression
CAST_TO_TEXT() StringExpression
CAST_TO_DATE() DateExpression
CAST_TO_TIME() TimeExpression
CAST_TO_TIMEZ() TimezExpression
CAST_TO_TIMESTAMP() TimestampExpression
CAST_TO_TIMESTAMPZ() TimestampzExpression
}
type expressionInterfaceImpl struct {
@ -55,6 +65,42 @@ func (e *expressionInterfaceImpl) DESC() orderByClause {
return &orderByClauseImpl{expression: e.parent, ascent: false}
}
func (e *expressionInterfaceImpl) CAST_TO_BOOL() BoolExpression {
return newBoolCast(e.parent)
}
func (e *expressionInterfaceImpl) CAST_TO_INTEGER() IntegerExpression {
return newIntegerCast(e.parent)
}
func (e *expressionInterfaceImpl) CAST_TO_DOUBLE() FloatExpression {
return newDoubleCast(e.parent)
}
func (e *expressionInterfaceImpl) CAST_TO_TEXT() StringExpression {
return newTextCast(e.parent)
}
func (e *expressionInterfaceImpl) CAST_TO_DATE() DateExpression {
return newDateCast(e.parent)
}
func (e *expressionInterfaceImpl) CAST_TO_TIME() TimeExpression {
return newTimeCast(e.parent)
}
func (e *expressionInterfaceImpl) CAST_TO_TIMEZ() TimezExpression {
return newTimezCast(e.parent)
}
func (e *expressionInterfaceImpl) CAST_TO_TIMESTAMP() TimestampExpression {
return newTimestampCast(e.parent)
}
func (e *expressionInterfaceImpl) CAST_TO_TIMESTAMPZ() TimestampzExpression {
return newTimestampzCast(e.parent)
}
func (e *expressionInterfaceImpl) serializeForGroupBy(statement statementType, out *queryData) error {
return e.parent.serialize(statement, out, NO_WRAP)
}