Hello, evenryone! I`m a novice with a little quest...
# exposed
a
Hello, evenryone! I`m a novice with a little question: how could I create a table`s column with a check constraint between values of two columns like in the example (
"limit" >= balance
):
Copy code
CREATE TABLE IF NOT EXISTS account (
  id          uuid PRIMARY KEY,
  balance     DECIMAL(16,2) NOT NULL DEFAULT 0 CHECK (balance >= 0),
  "limit"     DECIMAL(16,2) NOT NULL DEFAULT 0 CHECK ("limit" >= balance)
);
How could I get the current value of column here?
Copy code
object AccountTable : Table("account") {
...
val limit: Column<BigDecimal> = decimal("limit", 16, 2)
    .default(BigDecimal.ZERO)
    .check {it.greaterEq(??????)}
}
s
Copy code
object AccountTable : UUIDTable("account") {
    val balance = decimal("balance", 16, 2)
        .default(BigDecimal.ZERO)
        .check { it greaterEq BigDecimal.ZERO }
    val limit = decimal("limit", 16, 2)
        .default(BigDecimal.ZERO)
        .check { GreaterEqOp(it, balance) }
}
a
Thank you! That`s exactly what I needed