This code:

$sth_mlg_addr_duplicate_check->execute($fields[17],$fields[18],$fields +[19],$fields[20],$fields[21],$fields[22],$fields[23]) or warn "While checking for duplicate mailing address $fields[17 +]; $fields[19] $fields[20]: " . $dbh->errstr; ($mlg_addr_id) = $sth_mlg_addr_duplicate_check->fetchrow_array(); my $mlg_id; if(!defined($mlg_addr_id) && length($fields[20]) == 2){ $sth_insert_mlg_addr->execute($fields[17],$fields[18],$fields[19 +],$fields[20],$fields[21],$fields[22],$fields[23]) or warn "While inserting new mailing address |$fields[17]|; |$ +fields[19]| |$fields[20]|, with id |$mlg_addr_id|: " . $dbh->errstr; $sth_mlg_addr_duplicate_check->execute($fields[17],$fields[18],$ +fields[19],$fields[20],$fields[21],$fields[22],$fields[23]) or warn "While checking for duplicate mailing address |$fields +[17]|; |$fields[19]| |$fields[20]|: " . $dbh->errstr; ($mlg_addr_id) = $sth_mlg_addr_duplicate_check->fetchrow_array() +; $mlg_id = $mlg_addr_id; } else { $mlg_id = $mlg_addr_id; # print STDERR "\$mlg_addr_id is already defined as $mlg_addr_id +.\n"; }
is throwing this error:

Use of uninitialized value in concatenation (.) or string at parse_vot +er_list.pl line 251, <$fh> line 3483. While inserting new mailing address |xxxx RUE LOUIS PHILLIPPE|; |MARRE +RO| |LA|, with id ||: ERROR: duplicate key violates unique constrain +t "mlg_addr_uniq_key" While checking for duplicate mailing address |xxxx RUE LOUIS PHILLIPPE +|; |MARRERO| |LA|: ERROR: current transaction is aborted, commands i +gnored until end of transaction block While checking for duplicate residential address: ERROR: current tran +saction is aborted, commands ignored until end of transaction block Issuing rollback() for database handle being DESTROY'd without explici +t disconnect().
even though, after having done so, and from a psql prompt I'm getting:

=# SELECT * FROM mlg_addr WHERE address1 LIKE '%RUE LOUIS PHILLIPPE' A +ND city = 'MARRERO' AND state = 'LA'; mlg_addr_id | address1 | address2 | city | state | zipcode5 | zipcode +4 | country -------------+----------+----------+------+-------+----------+-------- +--+--------- (0 rows)
For the gruesome details:

my $mlg_addr_duplicate_check =<<EOQ; SELECT mlg_addr_id FROM mlg_addr WHERE address1 = ? AND address2 = ? AND city = ? AND state = ? AND zipcode5 = ? AND zipcode4 = ? AND country = ? EOQ my $sth_mlg_addr_duplicate_check = $dbh->prepare($mlg_addr_duplicate_c +heck) or die $dbh->errstr; my $insert_mlg_addr =<<EOQ; INSERT INTO mlg_addr (address1,address2,city,state,zipcode5,zipcode4,country) VALUES(?,?,?,?,?,?,?); EOQ my $sth_insert_mlg_addr = $dbh->prepare($insert_mlg_addr) or die $dbh- +>errstr;
and:

=# \d mlg_addr Table "public.mlg_addr" Column | Type | Modifie +rs -------------+-----------------------+-------------------------------- +--------------------------- mlg_addr_id | integer | not null default nextval(('mlg_ +addr_id'::text)::regclass) address1 | character varying(65) | address2 | character varying(65) | city | character varying(40) | state | character varying(2) | zipcode5 | character varying(5) | zipcode4 | character varying(4) | country | character varying(45) | Indexes: "mlg_addr_id_key" UNIQUE, btree (mlg_addr_id) "mlg_addr_uniq_key" UNIQUE, btree (country, zipcode5, zipcode4, ad +dress1, address2)
The @fields array includes the following fields:

address1 = $fields[17] address2 = $fields[18] city = $fields[19] state = $fields[20] zipcode5 = $fields[21] zipcode4 = $fields[22] country = $fields[13]
What am I missing? This is after this script has already run for twenty minutes, importing nearly 27,000 records, including 17,000 some records into this mlg_addr table.

Why would this query fail when there obviously is no duplicate in that table?

-- Hugh

UPDATE:

In response to moritz's questions about the details on the schema and the queries and variables, I've added some of the gruesome details behind the readmore tags.

if( $lal && $lol ) { $life++; }

In reply to duplicate key check isn't, why not? by hesco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.