2019-08-06 10:29:04 +02:00
|
|
|
package mysql
|
2019-08-03 14:10:47 +02:00
|
|
|
|
|
|
|
|
import "github.com/go-jet/jet/internal/jet"
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// ROW is construct one table row from list of expressions.
|
|
|
|
|
var ROW = jet.ROW
|
2019-08-03 14:10:47 +02:00
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// ------------------ Mathematical functions ---------------//
|
2019-08-06 10:29:04 +02:00
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// ABSf calculates absolute value from float expression
|
2019-08-03 14:10:47 +02:00
|
|
|
var ABSf = jet.ABSf
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// ABSi calculates absolute value from int expression
|
2019-08-03 14:10:47 +02:00
|
|
|
var ABSi = jet.ABSi
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// POW calculates power of base with exponent
|
|
|
|
|
var POW = jet.POW
|
|
|
|
|
|
|
|
|
|
// POWER calculates power of base with exponent
|
2019-08-03 14:10:47 +02:00
|
|
|
var POWER = jet.POWER
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// SQRT calculates square root of numeric expression
|
2019-08-03 14:10:47 +02:00
|
|
|
var SQRT = jet.SQRT
|
2019-08-06 10:29:04 +02:00
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// CBRT calculates cube root of numeric expression
|
2019-08-06 10:29:04 +02:00
|
|
|
func CBRT(number jet.NumericExpression) jet.FloatExpression {
|
|
|
|
|
return POWER(number, Float(1.0).DIV(Float(3.0)))
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// CEIL calculates ceil of float expression
|
2019-08-03 14:10:47 +02:00
|
|
|
var CEIL = jet.CEIL
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// FLOOR calculates floor of float expression
|
2019-08-03 14:10:47 +02:00
|
|
|
var FLOOR = jet.FLOOR
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// ROUND calculates round of a float expressions with optional precision
|
2019-08-03 14:10:47 +02:00
|
|
|
var ROUND = jet.ROUND
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// SIGN returns sign of float expression
|
2019-08-03 14:10:47 +02:00
|
|
|
var SIGN = jet.SIGN
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// TRUNC calculates trunc of float expression with precision
|
2019-08-06 10:29:04 +02:00
|
|
|
var TRUNC = TRUNCATE
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// TRUNCATE calculates trunc of float expression with precision
|
2019-08-06 10:29:04 +02:00
|
|
|
var TRUNCATE = func(floatExpression jet.FloatExpression, precision jet.IntegerExpression) jet.FloatExpression {
|
|
|
|
|
return jet.NewFloatFunc("TRUNCATE", floatExpression, precision)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// LN calculates natural algorithm of float expression
|
|
|
|
|
var LN = jet.LN
|
|
|
|
|
|
|
|
|
|
// LOG calculates logarithm of float expression
|
|
|
|
|
var LOG = jet.LOG
|
2019-08-03 14:10:47 +02:00
|
|
|
|
|
|
|
|
// ----------------- Aggregate functions -------------------//
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// AVG is aggregate function used to calculate avg value from numeric expression
|
|
|
|
|
var AVG = jet.AVG
|
|
|
|
|
|
|
|
|
|
// BIT_AND is aggregate function used to calculates the bitwise AND of all non-null input values, or null if none.
|
2019-08-03 14:10:47 +02:00
|
|
|
var BIT_AND = jet.BIT_AND
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// BIT_OR is aggregate function used to calculates the bitwise OR of all non-null input values, or null if none.
|
2019-08-03 14:10:47 +02:00
|
|
|
var BIT_OR = jet.BIT_OR
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// COUNT is aggregate function. Returns number of input rows for which the value of expression is not null.
|
|
|
|
|
var COUNT = jet.COUNT
|
|
|
|
|
|
|
|
|
|
// MAXi is aggregate function. Returns maximum value of int expression across all input values
|
2019-08-03 14:10:47 +02:00
|
|
|
var MAXi = jet.MAXi
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// MAXf is aggregate function. Returns maximum value of float expression across all input values
|
|
|
|
|
var MAXf = jet.MAXf
|
|
|
|
|
|
|
|
|
|
// MINi is aggregate function. Returns minimum value of int expression across all input values
|
2019-08-03 14:10:47 +02:00
|
|
|
var MINi = jet.MINi
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// MINf is aggregate function. Returns minimum value of float expression across all input values
|
|
|
|
|
var MINf = jet.MINf
|
|
|
|
|
|
|
|
|
|
// SUMi is aggregate function. Returns sum of expression across all integer expression.
|
2019-08-03 14:10:47 +02:00
|
|
|
var SUMi = jet.SUMi
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// SUMi is aggregate function. Returns sum of expression across all integer expression.
|
2019-08-06 10:29:04 +02:00
|
|
|
var SUMf = jet.SUMf
|
|
|
|
|
|
2019-08-03 14:10:47 +02:00
|
|
|
//--------------------- String functions ------------------//
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// BIT_LENGTH returns number of bits in string expression
|
2019-08-03 14:10:47 +02:00
|
|
|
var BIT_LENGTH = jet.BIT_LENGTH
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// CHAR_LENGTH returns number of characters in string expression
|
2019-08-03 14:10:47 +02:00
|
|
|
var CHAR_LENGTH = jet.CHAR_LENGTH
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// OCTET_LENGTH returns number of bytes in string expression
|
2019-08-03 14:10:47 +02:00
|
|
|
var OCTET_LENGTH = jet.OCTET_LENGTH
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// LOWER returns string expression in lower case
|
2019-08-03 14:10:47 +02:00
|
|
|
var LOWER = jet.LOWER
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// UPPER returns string expression in upper case
|
2019-08-03 14:10:47 +02:00
|
|
|
var UPPER = jet.UPPER
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// LTRIM removes the longest string containing only characters
|
|
|
|
|
// from characters (a space by default) from the start of string
|
2019-08-03 14:10:47 +02:00
|
|
|
var LTRIM = jet.LTRIM
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// RTRIM removes the longest string containing only characters
|
|
|
|
|
// from characters (a space by default) from the end of string
|
2019-08-03 14:10:47 +02:00
|
|
|
var RTRIM = jet.RTRIM
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// CONCAT adds two or more expressions together
|
2019-08-06 10:29:04 +02:00
|
|
|
var CONCAT = jet.CONCAT
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// CONCAT_WS adds two or more expressions together with a separator.
|
2019-08-06 10:29:04 +02:00
|
|
|
var CONCAT_WS = jet.CONCAT_WS
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// FORMAT formats a number to a format like "#,###,###.##", rounded to a specified number of decimal places, then it returns the result as a string.
|
2019-08-06 10:29:04 +02:00
|
|
|
var FORMAT = jet.FORMAT
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// LEFT returns first n characters in the string.
|
|
|
|
|
// When n is negative, return all but last |n| characters.
|
2019-08-03 14:10:47 +02:00
|
|
|
var LEFT = jet.LEFT
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// RIGHT returns last n characters in the string.
|
|
|
|
|
// When n is negative, return all but first |n| characters.
|
2019-08-03 14:10:47 +02:00
|
|
|
var RIGHT = jet.RIGHT
|
2019-08-06 10:29:04 +02:00
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// LENGTH returns number of characters in string with a given encoding
|
2019-08-06 10:29:04 +02:00
|
|
|
func LENGTH(str jet.StringExpression) jet.StringExpression {
|
|
|
|
|
return jet.LENGTH(str)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// LPAD fills up the string to length length by prepending the characters
|
|
|
|
|
// fill (a space by default). If the string is already longer than length
|
|
|
|
|
// then it is truncated (on the right).
|
2019-08-06 10:29:04 +02:00
|
|
|
func LPAD(str jet.StringExpression, length jet.IntegerExpression, text jet.StringExpression) jet.StringExpression {
|
|
|
|
|
return jet.LPAD(str, length, text)
|
|
|
|
|
}
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// RPAD fills up the string to length length by appending the characters
|
|
|
|
|
// fill (a space by default). If the string is already longer than length then it is truncated.
|
2019-08-06 10:29:04 +02:00
|
|
|
func RPAD(str jet.StringExpression, length jet.IntegerExpression, text jet.StringExpression) jet.StringExpression {
|
|
|
|
|
return jet.RPAD(str, length, text)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// MD5 calculates the MD5 hash of string, returning the result in hexadecimal
|
2019-08-03 14:10:47 +02:00
|
|
|
var MD5 = jet.MD5
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// REPEAT repeats string the specified number of times
|
2019-08-03 14:10:47 +02:00
|
|
|
var REPEAT = jet.REPEAT
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// REPLACE replaces all occurrences in string of substring from with substring to
|
2019-08-03 14:10:47 +02:00
|
|
|
var REPLACE = jet.REPLACE
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// REVERSE returns reversed string.
|
2019-08-03 14:10:47 +02:00
|
|
|
var REVERSE = jet.REVERSE
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// SUBSTR extracts substring
|
2019-08-03 14:10:47 +02:00
|
|
|
var SUBSTR = jet.SUBSTR
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// REGEXP_LIKE Returns 1 if the string expr matches the regular expression specified by the pattern pat, 0 otherwise.
|
|
|
|
|
var REGEXP_LIKE = jet.REGEXP_LIKE
|
2019-08-03 14:10:47 +02:00
|
|
|
|
|
|
|
|
//----------------- Date/Time Functions and Operators ------------//
|
2019-08-14 10:11:43 +02:00
|
|
|
// CURRENT_DATE returns current date
|
2019-08-03 14:10:47 +02:00
|
|
|
var CURRENT_DATE = jet.CURRENT_DATE
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// CURRENT_TIME returns current time with time zone
|
|
|
|
|
func CURRENT_TIME(precision ...int) TimeExpression {
|
|
|
|
|
return TimeExp(jet.CURRENT_TIME(precision...))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CURRENT_TIMESTAMP returns current timestamp with time zone
|
|
|
|
|
func CURRENT_TIMESTAMP(precision ...int) TimestampExpression {
|
|
|
|
|
return TimestampExp(jet.CURRENT_TIMESTAMP(precision...))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOW returns current datetime
|
2019-08-06 10:29:04 +02:00
|
|
|
func NOW(fsp ...int) DateTimeExpression {
|
|
|
|
|
if len(fsp) > 0 {
|
2019-08-16 11:19:06 +02:00
|
|
|
return jet.NewTimestampFunc("NOW", jet.ConstLiteral(int64(fsp[0])))
|
2019-08-06 10:29:04 +02:00
|
|
|
}
|
|
|
|
|
return jet.NewTimestampFunc("NOW")
|
|
|
|
|
}
|
2019-08-03 14:10:47 +02:00
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// TIMESTAMP return a datetime value based on the arguments:
|
2019-08-06 13:58:17 +02:00
|
|
|
func TIMESTAMP(str StringExpression) TimestampExpression {
|
|
|
|
|
return jet.NewTimestampFunc("TIMESTAMP", str)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
// UNIX_TIMESTAMP returns unix timestamp
|
2019-08-06 13:58:17 +02:00
|
|
|
func UNIX_TIMESTAMP(str StringExpression) TimestampExpression {
|
|
|
|
|
return jet.NewTimestampFunc("UNIX_TIMESTAMP", str)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 10:11:43 +02:00
|
|
|
//----------- Comparison operators ---------------//
|
|
|
|
|
|
|
|
|
|
// EXISTS checks for existence of the rows in subQuery
|
2019-08-03 14:10:47 +02:00
|
|
|
var EXISTS = jet.EXISTS
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
// CASE create CASE operator with optional list of expressions
|
2019-08-03 14:10:47 +02:00
|
|
|
var CASE = jet.CASE
|
2019-08-14 10:11:43 +02:00
|
|
|
|
|
|
|
|
//----------------- Bit operators ---------------//
|
|
|
|
|
|
|
|
|
|
var BIT_NOT = jet.BIT_NOT
|