Re: Update sql question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Don Isgitt <djisgitt(at)soundenergy(dot)com>
Cc: postgresql general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Update sql question
Date: 2005-06-07 16:49:44
Message-ID: 9645.1118162984@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Don Isgitt <djisgitt(at)soundenergy(dot)com> writes:
> Tom Lane wrote:
>> BTW, I find the "limit 1" a bit scary --- if there are multiple matches,
>> this coding will select a random one of them. Is that really what you
>> want?

> Ah, quite so. Thank you, Tom and Richard for your spot on help. Tom, I
> appreciate your concern for my limit 1; I confess it is a lazy way out.
> There are many multiple duplicate entries (oldopr and newopr), so rather
> than cleaning up the table, ...

Perhaps write the sub-select as

(select distinct newopr from opr_match
where state=master.state and oldopr=master.operator)

so that you'll get an error if there's more than one value for newopr in
the table. I'm not sure what performance hit you'll take, but checking
the data for self-consistency is a good idea in my book, especially when
you already know it's not very clean ...

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tim Vadnais 2005-06-07 16:58:18 Issue with adding ORDER BY to EXCEPT.
Previous Message Tom Lane 2005-06-07 16:42:03 Re: CPU-intensive autovacuuming