Re: Correct update statement

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Correct update statement
Date: 2014-05-15 08:42:15
Message-ID: 53747DE7.2080509@compulab.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<html style="direction: ltr;">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<style type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body style="direction: ltr;"
bidimailui-detected-decoding-type="UTF-8" bgcolor="#FFFFFF"
text="#000000">
<div class="moz-cite-prefix">update contacts set addr_id=b.addr_id <br>
from<br>
(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<br>
where contacts.con_id=b.con_id<br>
<br>
On 05/15/2014 09:19 AM, Khangelani Gama wrote:<br>
</div>
<blockquote
cite="mid:dd09ad0dac3046ab93e597688a2a31ff(at)mail(dot)gmail(dot)com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 14 (filtered
medium)">
<style><!--
/* 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;}
--></style>
<div class="WordSection1">
<p class="MsoNormal">Hi</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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 <b>addr_id </b>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</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Example:</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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;<br>
 cus_acno | con_id | addr_id <br>
----------+--------+---------<br>
   243492 | 119360 |  187479<br>
   393701 | 119824 |  458532<br>
   388538 | 118413 |  453178<br>
<br>
</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:&quot;Courier
New&quot;;color:blue" lang="EN-ZA"> </span><span
lang="EN-ZA"> </span></p>
<p class="MsoNormal">Thanks</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
</div>
<pre>
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.

</pre>
</blockquote>
<br>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 4.6 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Khangelani Gama 2014-05-15 09:22:16 Re: Correct update statement
Previous Message Craig Ringer 2014-05-15 08:31:48 TODO: Expose parser support for decoding unicode escape literals to user