UPDATE statement through perl - Mailing list pgsql-novice

From Devinder K Rajput
Subject UPDATE statement through perl
Date
Msg-id OFC968B16A.14B13EBD-ON86256C29.00721A3D@ipaper.com
Whole thread Raw
List 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


pgsql-novice by date:

Previous
From: "Devinder K Rajput"
Date:
Subject: UPDATE statement through perl
Next
From: Eric Walstad
Date:
Subject: Re: formatting a date when some nulls exist