Re: multiple sql update w/ major time issues

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: iu_23(at)hotmail(dot)com (Dawn)
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: multiple sql update w/ major time issues
Date: 2001-06-12 18:34:00
Message-ID: 12898.992370840@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

iu_23(at)hotmail(dot)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
set
EXTVALUE217 = 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Chris Ruprecht 2001-06-12 18:39:40 Re: rpt
Previous Message Alex Pilosov 2001-06-12 18:06:19 Re: audit trail and system catalogs