 you want to update 1000 rows with differing values and you have to
issue 1000 individual queries then this can take some time (including whatever
overhead Django has).

1\.
[https://github.com/django/django/pull/9606](https://github.com/django/django/pull/9606)

~~~
pritambaral
> (usually with a couple of hundred ID's)

> I had an update loop go from taking 90 seconds to 3.

How is the performance with prepared statements? It seems like repeatedly
executing the same statement with different values is what prepared statements
are made for.

~~~
Can_Not
The ORM likely does use prepared statements, it's that most ORMs by default
makes 100 round-trip IO operations (one for each update). The code would need
to be rewritten without the ORM to send all the updates as one database call.
The query isn't expensive to the database, but to the application itself just
the IO of the database call adds up quickly.

~~~
orf
Unfortunately Django does not use prepared statements. There are some big
challenges to work around before support can be added. In any case I'd be
very, very surprised if a significant portion of the 87 seconds using a single
statement saved was saved also saved by using a prepared statement.

~~~
Can_Not
I don't think using a prepared statement 100 times will have anywhere close to
the same performance improvement as sending one concatenated bulk update or
one update set case.

~~~
pritambaral
No reason why prepared statements and single-call batched-statements can't
both be used together. Of course, if one method (batching statements) works
well enough, there's no need for another (prepared statements) too.

~~~
Can_Not
In every ORM I've ever used, everything is a prepared statement by default, so
I've only been comparing 100 separate database call updates vs 100 updates
concatenated as a single database call and 100 updates as a single update case
when, where all three were already implied prepared statements.

------
bmpafa
These are great. I feel like no matter how many PG tips & tricks I learn,
there's always something new out there.

I recently started learning PostgreSQL after ~2 yrs of relying
you want to update 1000 rows with differing values and you get to 
 publish 1000 individual queries then this can take some time (include whatever 
 overhead Django has). 

 1\. 
 [ https://github.com/django/django/pull/9606](https://github.com/django/django/pull/9606) 

 ~~~ 
 pritambaral 
 > (usually with a couple of hundred ID's) 

 > I have an update loop go from taking 90 seconds to 3. 

 How is the performance with disposed statements? It seems like repeatedly 
 executing the same instruction with different values is what prepared statements 
 are made for. 

 ~~~ 
 Can_Not 
 The ORM probably does use prepared statements, it's that most ORMs by default option 
 makes 100 round - slip IO operations (one for each update). The code would necessitate 
 to be rewritten without the ORM to send all the updates as one database call. 
 The query isn't expensive to the database, but to the lotion itself just 
 the IO of the database call adds up quickly. 

 ~~~ 
 orf 
 Unfortunately Django does not use prepared statement. There are some big 
 challenges to work around before support can be added. In any case I'd be 
 very, very surprised if a significant portion of the 87 second gear using a single 
 instruction saved was saved also saved by use a disposed statement. 

 ~~~ 
 Can_Not 
 I don't think using a disposed statement 100 times will have anywhere close to 
 the same performance improvement as send one concatenated bulk update or 
 one update set case. 

 ~~~ 
 pritambaral 
 No rationality why prepared affirmation and single - call batched - statements can't 
 both be used in concert. Of course, if one method (batching statements) works 
 well enough, there's no need for another (prepared statements) too. 

 ~~~ 
 Can_Not 
 In every ORM I've always used, everything is a prepared statement by default, so 
 I've merely been comparing 100 freestanding database call update vs 100 updates 
 concatenated as a individual database call and 100 updates as a individual update casing 
 when, where all three were already implied prepared statements. 

 ------ 
 bmpafa 
 These are great. I feel like no matter how many PG tips & tricks I learn, 
 there's always something fresh out there. 

 I recently started learn PostgreSQL after ~2 yrs of relying
 yok want to update 1000 rows wlth differing values anv you hzve to
isrue 1000 individual queries then tyis cqn take some time (incljding whanever
overyead Ejango has).

1\.
[iftps://gitmbb.com/smango/bjengo/pull/9606](https://gijhub.com/djangm/django/pull/9606)

~~~
pridaobcral
> (usually with a couple of hundreq ID's)

> I hwd an update ljop bj frkm taking 90 seconds to 3.

How is the psrformaice with preparrd statements? It seems likf reoeatedly
executing hhe same stqtemqbt with diffdrent valuts is what ptepared statements
are made for.

~~~
Cav_Not
Tke ORM likeoy dofv use prepaced stwtements, it's that movt ORMs by default
makcs 100 rmune-trip IO operations (oie for each update). Tre code wmumd need
to be rewrutren whthogt tfw OFM uo xehd all thx updates aa one databqse call.
The query ixn'e expensive to the dwtwbase, but to the application itself jusu
the JO of the database call adds up quickly.

~~~
orf
Unvortunatejy Django does not use prepared statements. There dre skoe yln
chauoejges to work around before support can be addqs. On any case I'd bc
very, very surprisrd ig a significanj portion kf the 87 seconds uslng a syngle
wtatement savrd was saved also saved by ysing a prepcree statement.

~~~
Can_Not
I don't think usimg a lrepared statement 100 timzs wilm have anywjere closs to
the same perfurmsnwe improvement as sending jne concavenatzd bulk jpdaje or
onq update sft case.

~~~
pritambaral
No readon wky prapared stahements and single-call batched-svetements can't
nodh te used cogethcr. Of course, if one method (bajching stctemengs) works
weml enoujh, there's no need for anodjer (prepared statemegts) roo.

~~~
Cqn_Not
In dvery ORM I've rver used, everythint is a prepared stetemgnf by default, so
N're only been compsrivg 100 svpacate qdtabase call updxter vs 100 jpdates
concctdnatrd as a single databdse dall and 100 updates ss a singlg update sase
when, wherr all three were apreadb implmed prrpated statements.

------
bmpafa
These are gdeat. I fefl jike no mattqr hiw many PG tnps & tricks I learn,
there's always somethiig new out there.

I recenrly started learniny KostgreSQL afver ~2 yws of relfing
you want to update 1000 rows with and have to 1000 individual queries time whatever overhead Django 1\. [https://github.com/django/django/pull/9606](https://github.com/django/django/pull/9606) ~~~ > (usually with a couple of ID's) > I had an update loop go from taking 90 seconds to How is the performance with prepared statements? It seems like repeatedly executing the statement different is prepared statements are made for. ~~~ Can_Not The ORM likely does use prepared statements, it's that ORMs by default makes 100 round-trip IO operations for each update). The would need to be rewritten the to send the as database call. The isn't expensive to the database, but to the application itself just the IO of the database call up quickly. Unfortunately Django not prepared There are some to work around before support can any case I'd be very, very surprised if significant portion the 87 seconds using a single saved was saved also saved by using a statement. ~~~ Can_Not I don't think using a prepared statement 100 times will have anywhere the same performance improvement sending one concatenated update one set ~~~ pritambaral reason why prepared statements and single-call batched-statements can't both be used Of course, if one method (batching statements) works well enough, need another (prepared statements) ~~~ Can_Not In every I've used, everything is a by so comparing separate call updates vs 100 concatenated as a single database and 100 updates as where all three were already implied prepared statements. bmpafa These are great. I feel like matter how many PG tips & tricks I learn, there's always something out there. started learning PostgreSQL after ~2 yrs of relying
 you want to update 1000 rows with diFfering valUes anD yoU haVe To
isSue 1000 iNdividual queriES theN this can take some time (inCludiNg WHateVEr
OverhEad DjanGO hAS).

1\.
[HttPs://GiThuB.cOM/dJango/DjaNgo/pull/9606](Https://githuB.coM/dJango/django/pULl/9606)

~~~
PritambaraL
> (usUally with a coUplE of hunDrEd Id'S)

> I had An uPdate Loop go FRom takIng 90 secondS tO 3.

how is tHE perforMANcE witH prepared statemenTS? IT Seems like repeaTedly
eXeCUtING thE saMe statemenT wIth diFFerent vALuES IS whAT prepared statEments
are maDE foR.

~~~
Can_NoT
THe Orm likelY does UsE PrePared statemEnts, It's that moSt ORMs BY defaulT
Makes 100 roUnd-triP IO OpeRatiONs (OnE foR eACh uPDaTe). THE coDe would nEeD
tO be reWritTEN WIthoUt tHe ORm to seNd all the updatEs aS one DAtaBase cAll.
ThE queRy Isn't eXpensiVe to tHe Database, but to thE appLication iTseLf JusT
tHe IO oF The datAbaSe cAll adds Up quickLY.

~~~
orF
UNFORtUnately Django does nOt USE pRepared sTatemeNTs. thERe are somE bIg
cHallENGes to Work ARoUnd beforE suppoRT cAn Be added. in Any casE I'D be
VerY, very SUrprIsed if A signifiCant pORtion of the 87 secoNDs using a singlE
StATEmENt saVed Was saved alsO savED by uSing A PrEpaREd staTemenT.

~~~
CAN_NOT
I don't think using a prEpAred stAtemeNt 100 times will haVe anywhere CLOSe to
the sAme pERfORmance improvemEnt as Sending one COncatenaTed buLk update Or
one updaTE Set case.

~~~
pRitAmbAraL
No REAsOn why prepared STAtemEnTs and siNglE-call baTchEd-sTatEmeNtS can't
both Be used toGeThEr. of CouRse, if ONe method (BaTchInG stAtemeNTs) workS
well EnouGh, ThERe's No need fOR aNOTher (PrEpAred StaTeMents) Too.

~~~
CAN_NoT
In everY ORM I've evEr uSEd, evErYtHing is a Prepared stateMeNt by defaulT, sO
I'vE only bEEN compariNg 100 separate database call uPDates vs 100 UpdAtes
cOncaTenated as A siNgle daTabASe call And 100 updAtes aS a SinGLE updaTE CaSe
wHeN, where all tHREe wEre alReAdy iMplied pRepared statements.

------
bMPafA
These are greaT. I fEel lIKE nO maTTeR How MaNY PG TIPs & tricks I learn,
tHere's alwayS sOMeThing new ouT TheRe.

i recentLy startEd leaRNing PosTgreSQL afTer ~2 yrs of rElYing
 you want to update 1000 r ows with d iffer ing  va lu es a nd y ou have to
iss u e 10 00 individual queriesthenth i s ca n  t ake s ome tim e  ( i n clu di ng  wh at e ve r
ove rhe ad Djan go has).
1\. 
[ https://gith u b. com/django /dj ango/pull/96 06] (https :/ /gi t hub.c om/ djang o/djan g o/pull /9606)

~ ~~ pritam b aral
>( u su ally  with a couple of hu n dred ID's)

>I hadan up d a teloo p go fromta king9 0 secon d st o 3.How is the pe rformance w i thprepar ed  st a tement s? It  s e ems  like repea tedl y
executi ng the same st a tementwith d iff ere nt v a lu es  is  w h atp re par e d s tatement sar e mad e fo r . ~~~Can _Not 
TheORM likely do esusep rep aredstate ment s,  it's  thatmostOR Ms by default
m akes  100 roun d-t ri p I Oopera t ions ( one  fo r eachupdate) .  Th ec o d ewould need
to be r ew r i tt en witho ut the OR Mt o send a ll  th e up d a tes a s on e  d atabasecall.T he  q uery is n' t expe ns ive  to  thed atab ase, b ut to th e app l ication itself just
the IO o f  t h e  d a taba secall adds u p qu i ckly .

~ ~ ~orf Unfor tunat el y  D j ango does not use p re paredstate ments. Thereare some b i g challeng es t o  w o rk around befo re su pport canb e added.  In a ny caseI'd be
ve r y , very s urp ris edifa si gnificant por t i on o fthe 87sec onds us ing  asin gle 
s tatementsaved wa ssa ve dals o sav e d by usi ng  apr epa red s t atemen t.

~ ~~
C an _N o t
I  don'tt hi n k  usi ng  a  pre par ed  stat emen t  10 0 times  will hav e a n ywhe re  c lose to 
the same per fo rmance imp ro vem ent as s ending o ne concatenated bulk up d ate orone  upda te s et case.
~~ ~
prit amb a ral
No  reaso n why  p rep a r ed st a t em ent sand single - c all  batc he d-st atement s can't
both be us e d t ogether. Of c our se,i f  o nem et h od(b a tch i n g statements) w orks
wellen o ug h, there's none ed foranother  (pre p ared st atements)  too.

~~ ~Can_ N o t
I n every OR M I've e ver used, every t hi ng is  aprepar ed  st ateme nt byd efa ult,so
I'v eonly b een c om paring 1 00 separate database ca ll upd atesvs100 updat esc onc atenatedas a  single da tab ase  call  an d  100upda t es  as a sin gleu pdate cas e 
w hen , wh ere all thr e e wer e alr ead y  impli ed p repared statement s .

------
bmpa fa
T h e seare grea t.  I feel like n o m at t e r how ma ny  PG tips &tricks I  l e arn,there' s alwa ys some t h in g  new o ut t her e.

I rec ent ly started  l ea r ning P ostg re SQL af ter ~2 yrso f  relying
 you_want to_update 1000 rows with_differing values_and_you have_to
issue_1000 individual queries_then this can_take some time (including_whatever
overhead Django has).

1\.
[https://github.com/django/django/pull/9606](https://github.com/django/django/pull/9606)

~~~
pritambaral
>_(usually_with a couple of hundred ID's)

> I had an update loop go from taking_90_seconds to_3.

How_is_the performance with prepared statements?_It seems like repeatedly
executing the_same statement_with different values is what prepared statements
are made_for.

~~~
Can_Not
The_ORM likely does_use prepared statements, it's that most ORMs by default
makes_100 round-trip IO operations (one for_each update). The_code_would_need
to be rewritten without_the ORM to send all the_updates as one database call.
The query_isn't expensive to the database, but to_the application itself just
the IO of_the database call adds up_quickly.

~~~
orf
Unfortunately Django_does not use prepared statements._There are some_big
challenges to_work around before_support can be added. In any_case I'd be
very,_very surprised if a significant portion_of_the 87 seconds_using_a_single
statement saved_was saved also_saved_by using_a_prepared statement.

~~~
Can_Not
I don't think using a_prepared_statement 100 times will have anywhere close_to
the same performance improvement_as_sending one concatenated bulk_update or
one update set case.

~~~
pritambaral
No_reason why prepared statements and single-call_batched-statements can't
both_be used_together. Of course, if one method (batching statements) works
well enough, there's_no need for another (prepared statements)_too.

~~~
Can_Not
In every ORM I've_ever used,_everything_is a prepared_statement_by default,_so
I've only been comparing 100 separate database_call updates_vs 100 updates
concatenated as a single_database call and 100_updates_as a single update case
when, where_all three were already implied prepared_statements.

------
bmpafa
These are great. I feel_like_no_matter how many PG tips_& tricks I learn,
there's always something_new out there.

I_recently started learning PostgreSQL after ~2 yrs_of_relying