On Feb 20, 2:19 pm, galago wrote:
> What is the best way, to select X random rows from DB? I know that
> method: .all().order_by('?')[:X] is not good idea.
> What methods do you use?
order_by('RAND()')
That might use the same seed each time.
To create, for examp
If you know this is going to be an important part of the application, it might
make sense to have a random primary key, such as a UUID.
--
-- Christophe Pettus
x...@thebuild.com
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this
Please see my previous post with the django snippet for more info on this
method (as it uses this same principle).
On Mon, Feb 21, 2011 at 10:06 PM, Mikhail Korobov wrote:
> This is the function for getting 1 item that works even if some rows
> were deleted that works times faster than order_by('
Stackoverflow:
http://stackoverflow.com/questions/962619/how-to-pull-a-random-record-using-djangos-orm/971671#971671
On 22 фев, 03:06, Mikhail Korobov wrote:
> This is the function for getting 1 item that works even if some rows
> were deleted that works times faster than order_by('?') even for
This is the function for getting 1 item that works even if some rows
were deleted that works times faster than order_by('?') even for not-
so-big datasets at least on mysql:
def get_random_item(model, max_id=None):
if max_id is None:
max_id = model.objects.aggregate(Max('id')).values()
I need to do this in my tagcloud.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For m
On Feb 21, 2011, at 10:34 AM, Eric Chamberlain wrote:
> If you have lots of rows, this query is really slow as the db must build a
> new table for the ORDER BY.
You can do better if you have a guaranteed ordinal on the rows; otherwise, it
has to do a full table scan no matter what.
--
-- Chris
On Feb 20, 2011, at 4:30 PM, Christophe Pettus wrote:
>
> On Feb 20, 2011, at 2:19 PM, galago wrote:
>
>> What is the best way, to select X random rows from DB? I know that method:
>> .all().order_by('?')[:X] is not good idea.
>
> The best way is to p
eb 20, 2011, at 2:19 PM, galago wrote:
>
> > What is the best way, to select X random rows from DB...
>
> The best way is to push it onto the DB, using a raw query:
>
>random_results = Table.objects.raw("SELECT * FROM table ORDER BY
> random() LIMIT X")
&g
On Feb 20, 2011, at 2:19 PM, galago wrote:
> What is the best way, to select X random rows from DB? I know that method:
> .all().order_by('?')[:X] is not good idea.
The best way is to push it onto the DB, using a raw query:
random_results = Table.objects.raw("SELE
om MTN
>> --
>> *From: * galago
>> *Sender: * django-users@googlegroups.com
>> *Date: *Sun, 20 Feb 2011 14:24:37 -0800 (PST)
>> *To: *
>> *ReplyTo: * django-users@googlegroups.com
>> *Subject: *Re: Select x random rows from D
ireless device from MTN
> --
> *From: * galago
> *Sender: * django-users@googlegroups.com
> *Date: *Sun, 20 Feb 2011 14:24:37 -0800 (PST)
> *To: *
> *ReplyTo: * django-users@googlegroups.com
> *Subject: *Re: Select x random rows from DB
>
> If i knew what is a good idea, I
@googlegroups.com
Date: Sun, 20 Feb 2011 14:24:37
To:
Reply-To: django-users@googlegroups.com
Subject: Re: Select x random rows from DB
If i knew what is a good idea, I wouldn't aks here:D
I only know - that described method is DB killer :)
--
You received this message because you are subscrib
10:19 PM, galago wrote:
> What is the best way, to select X random rows from DB? I know that
> method: .all().order_by('?')[:X] is not good idea.
> What methods do you use?
>
> --
> You received this message because you are subscribed to the Google Groups
> &q
ly-To: django-users@googlegroups.com
Subject: Select x random rows from DB
What is the best way, to select X random rows from DB? I know that
method: .all().order_by('?')[:X] is not good idea.
What methods do you use?
--
You received this message because you are subscribed to the Google
If i knew what is a good idea, I wouldn't aks here:D
I only know - that described method is DB killer :)
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this
What is the best way, to select X random rows from DB? I know that
method: .all().order_by('?')[:X] is not good idea.
What methods do you use?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send e
17 matches
Mail list logo