Esquleto : 'ORDER BY random()'?

Hi all (and specifically Felipe), I'm wonder who to implement the following SQL in Esqueleto: SELECT * FROM table WHERE field = X ORDER BY RANDOM() LIMIT N I noticed that there is a random_ function and I figured out how to use it by reading the tests, but it doesn't seem to be useful in the above context. Clues? Maybe Esqueleto needs an 'orderByRandom'. Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

I'm on my phone and didn't test it, but can't you use
orderBy [asc random_]
? On your SQL the ASC is implicit.
Cheers, =]
--
Felipe.
Enviado do meu Nexus 4.
Em 12/07/2013 03:45, "Erik de Castro Lopo"
Hi all (and specifically Felipe),
I'm wonder who to implement the following SQL in Esqueleto:
SELECT * FROM table WHERE field = X ORDER BY RANDOM() LIMIT N
I noticed that there is a random_ function and I figured out how to use it by reading the tests, but it doesn't seem to be useful in the above context.
Clues? Maybe Esqueleto needs an 'orderByRandom'.
Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

Felipe Almeida Lessa wrote:
I'm on my phone and didn't test it, but can't you use
orderBy [asc random_]
? On your SQL the ASC is implicit.
Not quite! Too tired to chase this now. Time for bed :-). Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

On 12 Jul 2013, at 14:25, Erik de Castro Lopo wrote (with possible deletions):
Felipe Almeida Lessa wrote:
I'm on my phone and didn't test it, but can't you use
orderBy [asc random_]
? On your SQL the ASC is implicit.
What's nice about the relational model is that it gives you "ORDER BY random()" *anytime* you access the rows of a table. :-)
Not quite! Too tired to chase this now. Time for bed :-).
Sleep well, --Torsten -- | Prof. Dr. Torsten Grust | Database Systems — Universität Tübingen (Germany) | torsten.grust@uni-tuebingen.de | db.inf.uni-tuebingen.de

I've add a unit test that works with the SQLite used on the test suite
[1]. So I think that you may need an explicit type sig:
orderBy [asc (random_ :: SqlExpr (Value Double))]
Does that solve your problem?
[1] https://github.com/meteficha/esqueleto/commit/5545adc077947ec48f9d4261596cd7...
On Fri, Jul 12, 2013 at 9:25 AM, Erik de Castro Lopo
Felipe Almeida Lessa wrote:
I'm on my phone and didn't test it, but can't you use
orderBy [asc random_]
? On your SQL the ASC is implicit.
Not quite! Too tired to chase this now. Time for bed :-).
Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
_______________________________________________ database-devel mailing list database-devel@haskell.org http://www.haskell.org/mailman/listinfo/database-devel
-- Felipe.
participants (3)
-
Erik de Castro Lopo
-
Felipe Almeida Lessa
-
Torsten Grust