order by rand() doesn't scale too well unfortunately.
http://www.depesz.com/index.php/2007/09/16/my-thoughts-on-getting-random-row/
has some better approaches. It's postgres specific but the approach
should be generalizable by moving logic to client side.

On Aug 23, 8:30 pm, GustaV <[EMAIL PROTECTED]> wrote:
> Ok, I wanted to know if there was a way to do it with no database
> specific code.
>
> Then you are right :
> I'll first query the result count (unknown a priori) and then use a
> random python generated offset.
>
> If anyone has a better idea (in 1 request only), that would be great!
>
> On 23 août, 18:34, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
> > On Aug 23, 2008, at 12:10 PM, GustaV wrote:
>
> > > Hi all,
> > > Really, you do an amazing job on that stuff, it's a pleasure to work
> > > with!
>
> > > A short question though. It's possible to get a random order on
> > > selects in mysql using the RAND() in parameter of ORDER BY. I know
> > > similar (but different) was possible on others.
> > > What about sqlalchemy?
> > > The goal is to have only one result on the query, randomly.
>
> > if the function is RAND(), you'd just say
> > select.order_by(func.rand()).    If you're looking for just the first
> > result then you'd use limit/offset (the select() and Query()
> > constructs both support limit() and offset() methods for this).
>
> > I'm not familiar with the "random function" of other databases but the
> > same techniques apply.   SQLA could also could also support with a
> > "generic" version of this function which calls the correct rand()
> > function on each database, but only if very similar choices exist on
> > most backends.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to