The following should do:
Item.objects.bulk_create([
Item(pool_cd=pool_cd.unique_code)
for pool_cd in pool_cds
])
Le jeudi 4 septembre 2014 12:44:08 UTC-4, James P a écrit :
>
> I forgot to include the code where I set the pool codes to NOTFREE, here
> is the whole snippet.
>
> code_count
@googlegroups.com
Subject: Re: Best way to batch select unique ids out of pool for sequences
The issue is that a bulk create doesn't allow me to use my unique values for
each create which I need from the code pool. Does it?
On Thursday, September 4, 2014 10:42:52 AM UTC-6, James Schneider wrote:
The issue is that a bulk create doesn't allow me to use my unique values
for each create which I need from the code pool. Does it?
On Thursday, September 4, 2014 10:42:52 AM UTC-6, James Schneider wrote:
>
> You probably want to look at bulk_create and do all of the inserts as a
> single query:
I forgot to include the code where I set the pool codes to NOTFREE, here is
the whole snippet.
code_count=5000
pool_cds = CodePool.objects.filter(free_indicator=True)[:code_count]
for pool_cd in pool_cds:
new_item = Item.objects.create(
pool_cd=p
You probably want to look at bulk_create and do all of the inserts as a
single query:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#bulk-create
This will probably be seconds, if not minutes faster.
-James
On Thursday, September 4, 2014, James P wrote:
> I have what is essentiall
I have what is essentially a table which is a pool of available
codes/sequences for unique keys when I create records elsewhere in the DB.
Right now I run a transaction where I might grab 5000 codes out of an
available pool of 1 billion codes using the slice operator [:code_count]
where code_cou
6 matches
Mail list logo