Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Querydsl not support rand()?

Tags:

java

querydsl

I want to make SQL look like:

select b from Book b order by rand()

how convert that query to Querydsl query?

Is it not supported by Querydsl? If you know the way to support this query, please answer it..;

thank you.

like image 385
xyzlast Avatar asked Sep 01 '26 08:09

xyzlast


1 Answers

Querydsl SQL supports it via

NumberExpression.random()

So your query could be expressed like this

query.from(b)
    .orderBy(NumberExpression.random().asc())
    .list(b);

I am not sure how well it is supported for JPQL, it doesn't seem to be in the standard.

like image 113
Timo Westkämper Avatar answered Sep 03 '26 23:09

Timo Westkämper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!