Add Postgres generate_series function
This commit is contained in:
parent
6a0798eb06
commit
dfafd1482b
2 changed files with 22 additions and 0 deletions
|
|
@ -342,6 +342,15 @@ func DATE_TRUNC(field unit, source Expression, timezone ...string) TimestampExpr
|
||||||
return jet.NewTimestampFunc("DATE_TRUNC", jet.FixedLiteral(unitToString(field)), source)
|
return jet.NewTimestampFunc("DATE_TRUNC", jet.FixedLiteral(unitToString(field)), source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GENERATE_SERIES generates a series of values from start to stop, with a step size of step.
|
||||||
|
func GENERATE_SERIES(start Expression, stop Expression, step ...Expression) Expression {
|
||||||
|
if len(step) > 0 {
|
||||||
|
return jet.NewFunc("GENERATE_SERIES", []Expression{start, stop, step[0]}, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
return jet.NewFunc("GENERATE_SERIES", []Expression{start, stop}, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// --------------- Conditional Expressions Functions -------------//
|
// --------------- Conditional Expressions Functions -------------//
|
||||||
|
|
||||||
// COALESCE function returns the first of its arguments that is not null.
|
// COALESCE function returns the first of its arguments that is not null.
|
||||||
|
|
|
||||||
|
|
@ -21,3 +21,16 @@ func TestDATE_TRUNC(t *testing.T) {
|
||||||
"DATE_TRUNC('DAY', NOW() + INTERVAL '1 HOUR', 'Australia/Sydney')",
|
"DATE_TRUNC('DAY', NOW() + INTERVAL '1 HOUR', 'Australia/Sydney')",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGENERATE_SERIES(t *testing.T) {
|
||||||
|
assertSerialize(
|
||||||
|
t,
|
||||||
|
GENERATE_SERIES(NOW(), NOW().ADD(INTERVAL(10, DAY))),
|
||||||
|
"GENERATE_SERIES(NOW(), NOW() + INTERVAL '10 DAY')",
|
||||||
|
)
|
||||||
|
assertSerialize(
|
||||||
|
t,
|
||||||
|
GENERATE_SERIES(NOW(), NOW().ADD(INTERVAL(10, DAY)), INTERVAL(2, DAY)),
|
||||||
|
"GENERATE_SERIES(NOW(), NOW() + INTERVAL '10 DAY', INTERVAL '2 DAY')",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue