Update sql question

From: Don Isgitt <djisgitt(at)soundenergy(dot)com>
To: postgresql general <pgsql-general(at)postgresql(dot)org>
Subject: Update sql question
Date: 2005-06-07 14:41:45
Message-ID: 42A5B229.1090007@soundenergy.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

First, software info:

gds2=# select version();

version

--------------------------------------------------------------------------------------------------------
PostgreSQL 7.4 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.3
20030502 (Red Hat Linux 3.2.3-20)
(1 row)

Now, description of what I did and the results:

gds2=# begin;
BEGIN
gds2=# select count(*) from master where state='NM' and operator is null;
count
-------
0
(1 row)

gds2=# update master set operator=(select
coalesce(newopr,master.operator) from opr_match where state=master.state
and oldopr=master.operator limit 1) where state='NM' and operator is not
null;
UPDATE 88486
gds2=# select count(*) from master where state='NM' and operator is null;
count
-------
261
(1 row)

gds2=# rollback;
ROLLBACK

Now, what I was trying to do:

master table has ~1000000 records, opr_match~120000 records and each has
a state field. master has an operator field (among many others),
opr_match has an oldopr and newopr field. I want to update master
operator field iff opr_match.oldopr=master.operator; if no match, just
update to self. Fine.

What am I doing wrong that gives me the 261 null operator fields after
the update?

Thank you very much for your assistance.

Don

p.s. The "operator is not null" where clause is needed for other states
that do have null operator values.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2005-06-07 14:50:20 Re: Logging query plan for queries
Previous Message peter royal 2005-06-07 14:26:00 locking question - why is this not a deadlock?