CREATE TABLE IF NOT EXISTS events
(
id UUID NOT NULL,
type_id UUID,
PRIMARY KEY (id)
);
jood code:
val queryDsl = dslContext.select(EventFields).from(EVENTS)
.where(
(EVENTS.TYPE_ID.isNull)
.or(EVENTS.TYPE_ID.eq(query.typeId.id))
)
model id code:
import java.util.UUID
data class TypeId(val id: UUID) {
constructor (id: String) : this(UUID.fromString(id))
override fun toString(): String = id.toString()
}
Query:
where (“public”.”events”.”type_id” = cast(‘d0c6a2a7-2032-4dd7-b2b1-77a554262af7’ as uuid))
Why cast?
I tried to get rid of this casting as it affect my index performance
Dhayanand Baskar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.