【问题标题】:JOOQ - Java Math.max (x,y) equivalentJOOQ - Java Math.max (x,y) 等价物
【发布时间】:2021-06-03 14:56:56
【问题描述】:

我想创建一个 PostgreSQL 查询来更新下边界为零的多个列 (SMALLINT)。我正在考虑 Java 方法 Math.max(x,y)。像Math.max(columnValue, 0) 这样的东西。有DSL.greatest(x,y)的方法,看起来很完美。但是,这只接受 Field 对象作为参数。

例如:

dslContext
  .update(TABLE)
  .set(TABLE.COLUMN1, DSL.greatest(TABLE.COLUMN1.minus(1), (short) 0))
  .set(TABLE.COLUMN2, DSL.greatest(TABLE.COLUMN2.minus(1), (short) 0))
  ... some more
  .where(TABLE.ID.eq(tableId))
  .execute();

这会导致零处的编译错误。 是否可以从数字中创建 Field 对象?或者我怎样才能以其他方式实现这一目标?

感谢您的支持。

【问题讨论】:

    标签: postgresql jooq


    【解决方案1】:

    要么使用DSL.inline() 内联,要么使用DSL.val() 绑定变量。

    dslContext
      .update(TABLE)
      .set(TABLE.COLUMN1, DSL.greatest(TABLE.COLUMN1.minus(1), DSL.inline((short) 0)))
      .set(TABLE.COLUMN2, DSL.greatest(TABLE.COLUMN2.minus(1), DSL.inline((short) 0)))
      ... some more
      .where(TABLE.ID.eq(tableId))
      .execute();
    

    【讨论】:

      猜你喜欢
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 2021-05-01
      • 2014-01-08
      • 2012-06-03
      • 2013-01-15
      • 1970-01-01
      相关资源
      最近更新 更多