Re: Correct update statement - Mailing list pgsql-general
| From | Sim Zacks |
|---|---|
| Subject | Re: Correct update statement |
| Date | |
| Msg-id | 53747DE7.2080509@compulab.co.il Whole thread Raw |
| In response to | Correct update statement (Khangelani Gama <kgama@argility.com>) |
| Responses |
Re: Correct update statement
|
| List | pgsql-general |
body p { margin-bottom: 0cm; margin-top: 0pt; }
<body style="direction: ltr;"
bidimailui-detected-decoding-type="UTF-8" bgcolor="#FFFFFF"
text="#000000">
update contacts set addr_id=b.addr_id
from
(select distinct(cus_acno), contact.con_id, address.addr_id from
address join person using (addr_id) join cus using (per_id) join
link_contact using (cus_acno) join contact using (con_id) where
contact.addr_id is null) b
where contacts.con_id=b.con_id
On 05/15/2014 09:19 AM, Khangelani Gama wrote:
<blockquote
cite="mid:dd09ad0dac3046ab93e597688a2a31ff@mail.gmail.com"
type="cite">
<meta name="Generator" content="Microsoft Word 14 (filtered
medium)">
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
-->
Hi
Â
Please help, we are using postgreSQL 9.2.4.
I need to  update over 9000 rows. See the query below: A table
called contact has got addr_id field as null which is
incorrect. So now I need to update contact table for each
account (cus_acno is in cus table) where contact_addr_id is
null. For example using the first of the results below: I need
take set addr_id (in contact table) Â to 187479 where cus_acno
= 243492 and con_id = 119360
Â
Â
Example:
Â
select distinct(cus_acno), contact.con_id,
address.addr_id from address join person using (addr_id) joinÂ
cus using (per_id) join link_contact using (cus_acno) join
contact using (con_id) where contact.addr_id is null;
 cus_acno | con_id | addr_id
----------+--------+---------
  243492 | 119360 | 187479
  393701 | 119824 | 458532
  388538 | 118413 | 453178
Â
<span
style="font-size:10.0pt;font-family:"Courier
New";color:blue" lang="EN-ZA">Â <span
lang="EN-ZA">
Thanks
Â
Â
Â
CONFIDENTIALITY NOTICE
The contents of and attachments to this e-mail are intended for the addressee only, and may contain the confidential
information of Argility (Proprietary) Limited and/or its subsidiaries. Any review, use or dissemination thereof by
anyone
other than the intended addressee is prohibited.If you are not the intended addressee please notify the writer
immediately
and destroy the e-mail. Argility (Proprietary) Limited and its subsidiaries distance themselves from and accept no
liability
for unauthorised use of their e-mail facilities or e-mails sent other than strictly for business purposes.
pgsql-general by date: