UPDATE statement through perl

From: "Devinder K Rajput" <Devinder(dot)Rajput(at)ipaper(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: UPDATE statement through perl
Date: 2002-09-03 21:00:21
Message-ID: OF7D5B9719.5D2EE60B-ON86256C29.00733B6B@ipaper.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,
I am trying to do an UPDATE via a perl script to multiple records.
However, the query only updates the first record and then breaks out of the
code. How can I get it to update the rest of the records. Please help.
Here is the code:

$result = $conn->exec("SELECT prime_vendor, \
number, \
hub_id \
FROM items \
ORDER BY prime_vendor, number, hub_id \
");
if(PGRES_TUPLES_OK ne $result->resultStatus){
print "Could not execute SELECT statement.\n";
print "Error: ", $conn->errorMessage;
print "Exiting...\n";
exit(-1);
}

while(@row=$result->fetchrow){
$group=2;
$result = $conn->exec("UPDATE items
SET vendor_group = " . $group . " \
WHERE prime_vendor = '" . $row[PRIME_VENDOR] .
"' \
and number = '" . $row[ITEM_NUMBER] . "'
\
and hub_id = " . $row[HUB_ID] . " \
");
}

The actual processing is little bit more complex, but essentially it
assigns the variable $group to the vendor_group field. The UPDATE query is
the part that is not working.

Devinder Rajput
Stores Division Corporate Offices
Chicago, IL
(773) 442-6474

Browse pgsql-novice by date

  From Date Subject
Next Message Alvaro Herrera 2002-09-04 03:29:42 Re: [GENERAL] PostgreSQL papers
Previous Message Devinder K Rajput 2002-09-03 20:51:12 UPDATE statement through perl