Re: multiple sql update w/ major time issues - Mailing list pgsql-sql

From Tom Lane
Subject Re: multiple sql update w/ major time issues
Date
Msg-id 12898.992370840@sss.pgh.pa.us
Whole thread Raw
In response to multiple sql update w/ major time issues  (iu_23@hotmail.com (Dawn))
List pgsql-sql
iu_23@hotmail.com (Dawn) writes:
> I have a sql update statement that is dealing with hundreds of
> thousands of records.  It takes hours and hours to complete (if it
> does complete and not take down the server).

No wonder, if you write it like that.  You're forcing a fresh select
from gl_totals for each row of aud_member_ext_attributes; then you're
doing it again for each UPDATE command.

If you were using Postgres (which I surmise you are not, because it
doesn't accept aliases in UPDATE) you could do

update aud_member_ext_attributes
setEXTVALUE217 = gl_totals.MTD,EXTVALUE223 = gl_totals.YTD,EXTVALUE229 = gl_totals.R12
where gl_totals.category = 'tankrent' and gl_totals.CUST_NO = EXTVALUE101 and gl_totals.DIST_NO = EXTVALUE102 and
gl_totals.SUB_NO= EXTVALUE105 and gl_totals.FUEL_TYPE = EXTVALUE123;
 
        regards, tom lane


pgsql-sql by date:

Previous
From:
Date:
Subject: Re: Getting row with id=max(id)
Next
From: Gerald Gutierrez
Date:
Subject: Are SQL commands "atomic" ?