spring-projects / spring-projects/spring-data-relational

Introduce support to compare two columns in `Criteria`

Open
#1,335 4 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

type: enhancement
Dominant language
Java
Stars
827
Forks
394
PR merge metrics
No merged PRs in 30d

Description

I'm trying to build a criteria where the resulting SQL should look something like;

OR (start_time = end_time AND start_time >= $1 AND start_time < $2)

The code I'm currently using is;

val startCol = Criteria.where("start_time")
val endCol = Criteria.where("end_time")

startCol.isEqual(startTime)
    .or(
        startCol.`is`(endCol)
            .and(startCol.greaterThanOrEquals(startTime))
            .and(startCol.lessThan(endTime))
    )
)

But unfortunately startCol.`is`(endCol) is not working, because it tries to process the endCol as a value.

I've also tried using SQL.literalOf("end_time") and Column.create("end_time", Table.create("appointments")), but both without success.

Is there a different syntax that can be used to compare 2 columns with each other?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.