Hey there, is there a way to achieve this composit...
# exposed
v
Hey there, is there a way to achieve this composite where clause with exposed?
Copy code
WHERE (updated_at, id) <= ('2020-01-04 15:51:38.862000', '79a4f222-69ea-439c-90ba-348d025166ef')
t
I think you can try andWhere clause
v
it does not reproduce the same result in Postgres (composite x and)
t
Can you send the query that you wrote with andWhere
v
isnt it
andWhere
suposed to add a AND clause?
If anyone in the future needs it, this is what I endend up with:
Copy code
/**
 * Expression to aggregate the [first] with the [second] columns of the composition
 */
class AnonymousCompositeExpression<L, R>(val first: Column<L>, val second: Column<R>) : Expression<Pair<L, R>>() {
    override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder {
        append("(${first.name}, ${second.name})")
    }
}

/**
 * Function to check if [this] composition is less or equal than the given [pair]
 */
infix fun <L, R> AnonymousCompositeExpression<L, R>.lessEq(pair: Pair<L, R>): Op<Boolean> = CompositeLessEqOP(this, pair, CompositeLessEqOP.Operation.LESS_EQ)

/**
 * Aggregate [this] column to [another] column creating an anonymous composite type
 */
infix fun <L, R> Column<L>.to(another: Column<R>) = AnonymousCompositeExpression(this, another)

/**
 * Creates a less or equals clause for [expr] columns against the given [pair]
 */
class CompositeLessEqOP<L, R>(val expr: AnonymousCompositeExpression<L, R>, val pair: Pair<L, R>, val operation: Operation) : Op<Boolean>() {
    enum class Operation(val symbol: String) {
        LESS_EQ("<="),
        GREATER_EQ(">=")
    }

    override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder {
        append("$expr ${operation.symbol} (")
        registerArgument(expr.first.columnType, pair.first)
        append(", ")
        registerArgument(expr.second.columnType, pair.second)
        append(")")
    }
}