/** * Subtract an interval from a date. * <p> * This translates into any dialect * * @see Field#add(Field) */ @Support public static Field<LocalDate> localDateSub(Field<LocalDate> date, Field<? extends Number> interval) { return nullSafe(date).sub(interval); }
/** * Subtract an interval from a timestamp. * <p> * This translates into any dialect * * @see Field#sub(Field) */ @Support public static Field<LocalDateTime> localDateTimeSub(Field<LocalDateTime> timestamp, Field<? extends Number> interval) { return nullSafe(timestamp).sub(interval); }
/** * Subtract an interval from a date. * <p> * This translates into any dialect * * @see Field#add(Field) */ @Support public static Field<Date> dateSub(Field<Date> date, Field<? extends Number> interval) { return nullSafe(date).sub(interval); }
/** * Subtract an interval from a timestamp. * <p> * This translates into any dialect * * @see Field#sub(Field) */ @Support public static Field<Timestamp> timestampSub(Field<Timestamp> timestamp, Field<? extends Number> interval) { return nullSafe(timestamp).sub(interval); }
@Override final Field<T> getFunction0(Configuration configuration) { switch (configuration.dialect()) { case SQLITE: return DSL.round(argument.sub(0.499999999999999)); default: return DSL.field("{floor}({0})", getDataType(), argument); } } }
@Override final Field<T> getFunction0(Configuration configuration) { switch (configuration.dialect()) { /* [pro] xx xxxx xxxxxxx xx [/pro] */ case SQLITE: return DSL.round(argument.sub(0.499999999999999)); default: return field("{floor}({0})", getDataType(), argument); } } }
private static final FieldOrRow parseSum(ParserContext ctx, Type type) { FieldOrRow r = parseFactor(ctx, type); if (N.is(type) && r instanceof Field) for (;;) if (parseIf(ctx, '+')) r = ((Field) r).add((Field) parseFactor(ctx, type)); else if (parseIf(ctx, '-')) r = ((Field) r).sub((Field) parseFactor(ctx, type)); else break; return r; }
private final QueryPart delegate(Configuration configuration) { switch (configuration.family()) { case CUBRID: // There is a bug in CUBRID preventing reuse of "level" in the // predicate http://jira.cubrid.org/browse/ENGINE-119 if (step == null) return table("({select} {0} {as} {1} {from} {2} {connect by} {level} <= {3})", from.add(level()).sub(one()), name("generate_series"), new Dual(), to.add(one()).sub(from)); else return table("({select} {0} {as} {1} {from} {2} {connect by} {level} * {3} <= {4})", from.add(level().mul(step)).sub(step), name("generate_series"), new Dual(), step, to.add(step).sub(from)); case POSTGRES: default: if (step == null) return table("{generate_series}({0}, {1})", from, to); else return table("{generate_series}({0}, {1}, {2})", from, to, step); } }
private final QueryPart delegate(Configuration configuration) { switch (configuration.dialect().family()) { case CUBRID: /* [pro] xx xxxx xxxxxxx xx [/pro] */ // There is a bug in CUBRID preventing reuse of "level" in the // predicate http://jira.cubrid.org/browse/ENGINE-119 Field<Integer> level = from.add(level()).sub(one()); return table("({select} {0} {as} {1} {from} {2} {connect by} {level} <= {3})", level, name("generate_series"), new Dual(), to.add(one()).sub(from)); case POSTGRES: default: return table("{generate_series}({0}, {1})", from, to); } }
/** * Get the hyperbolic cotangent function: coth(field). * <p> * This is not supported by any RDBMS, but emulated using exp exp: * <code><pre>(exp([field] * 2) + 1) / (exp([field] * 2) - 1)</pre></code> */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) public static Field<BigDecimal> coth(Field<? extends Number> field) { field = nullSafe(field); return exp(field.mul(2)).add(1).div(exp(field.mul(2)).sub(1)); }
switch (configuration.family()) { case DERBY: return DSL.substring(field, field.length().add(one()).sub(length));
/** * Get the hyperbolic cotangent function: coth(field). * <p> * This is not supported by any RDBMS, but simulated using exp exp: * <code><pre>(exp([field] * 2) + 1) / (exp([field] * 2) - 1)</pre></code> */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) @Transition( name = "COTH", args = "Field", to = "MathFunction" ) public static Field<BigDecimal> coth(Field<? extends Number> field) { field = nullSafe(field); return exp(field.mul(2)).add(1).div(exp(field.mul(2)).sub(1)); }
@SuppressWarnings({ "unchecked" }) @Override public void accept(Context<?> ctx) { switch (ctx.family()) { case POSTGRES: ctx.visit(DSL.field("{width_bucket}({0}, {1}, {2}, {3})", getType(), field, low, high, buckets)); break; default: ctx.visit( DSL.when(field.lt(low), zero()) .when(field.ge(high), buckets.add(one())) .otherwise((Field<Integer>) DSL.floor(field.sub(low).mul(buckets).div(high.sub(low))).add(one())) ); break; } }
@Override final Field<BigDecimal> getFunction0(Configuration configuration) { switch (configuration.family()) { case CUBRID: case HSQLDB: case MARIADB: case MYSQL: case POSTGRES: return DSL.exp(argument.mul(two())).sub(one()).div(DSL.exp(argument).mul(two())); default: return function("sinh", SQLDataType.NUMERIC, argument); } } }
return DSL.position(DSL.substring(in, startIndex), search).add(startIndex).sub(one());
@Override final Field<BigDecimal> getFunction0(Configuration configuration) { switch (configuration.family()) { case CUBRID: case HSQLDB: case MARIADB: case MYSQL: case POSTGRES: return DSL.exp(argument.mul(two())).sub(one()).div(DSL.exp(argument.mul(two())).add(one())); default: return function("tanh", SQLDataType.NUMERIC, argument); } } }
@Override final QueryPart getFunction0(Configuration configuration) { switch (configuration.dialect().family()) { case DERBY: return DSL.substring(field, field.length().add(one()).sub(length)); /* [pro] xx xxxx xxxxxxx xx [/pro] */ case SQLITE: return DSL.substring(field, length.neg()); /* [pro] xx xxxx xxxx xxxx xxxxxxx xxxx xxxxxxxxxx xxxx xxxxxxx xx [/pro] */ case CUBRID: case FIREBIRD: case H2: case HSQLDB: case MARIADB: case MYSQL: case POSTGRES: default: return field("{right}({0}, {1})", field, length); } } }
@Override final Field<BigDecimal> getFunction0(Configuration configuration) { switch (configuration.dialect().family()) { /* [pro] xx xxxx xxxxxxx xxxx xxxx xxxx xxxxxxx xxxx xxxxxxxxxx xxxx xxxxxxx xx [/pro] */ case CUBRID: case HSQLDB: case MARIADB: case MYSQL: case POSTGRES: return DSL.exp(argument.mul(two())).sub(one()).div(DSL.exp(argument).mul(two())); default: return function("sinh", SQLDataType.NUMERIC, argument); } } }
@Override final Field<BigDecimal> getFunction0(Configuration configuration) { switch (configuration.dialect().family()) { /* [pro] xx xxxx xxxxxxx xxxx xxxx xxxx xxxxxxx xxxx xxxxxxxxxx xxxx xxxxxxx xx [/pro] */ case CUBRID: case HSQLDB: case MARIADB: case MYSQL: case POSTGRES: return DSL.exp(argument.mul(two())).sub(one()).div(DSL.exp(argument.mul(two())).add(one())); default: return function("tanh", SQLDataType.NUMERIC, argument); } } }
return date1.sub(date2).cast(Integer.class);