mysqlperlinsertdbi

dup entry when doing insert into mysql from perl


i'm doing an insert into a mysql db from perl. i'm getting a duplicate error after the 1st insert. here is the code i'm using for the insert. i'm pulling an id from a json response. i have output of what i'm receiving below the code

  foreach my $listing(@{$json_text->{listings}})
    {
      my $id = $listing->{id};
   print "\nid = $id \n";


    # DO THE INSERT
    my $query_insert = "INSERT INTO calendar (id) VALUES ($id)";
    print "query insert = $query_insert \n";
    my $query = $db->do($query_insert); 
   print "query = $query \n";

    } #end foreach

here is the output i'm receiving. (returns didn't copy over right. so the below looks off, but the right data is there). this is like 133 my $query = $db->do($query_insert);

id = 2576246314 query insert = INSERT INTO calendar (id) VALUES (2576246314) query = 1

id = 2576246678 query insert = INSERT INTO calendar (id) VALUES (2576246678) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576246781 query insert = INSERT INTO calendar (id) VALUES (2576246781) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576247610 query insert = INSERT INTO calendar (id) VALUES (2576247610) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576247737 query insert = INSERT INTO calendar (id) VALUES (2576247737) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576247756 query insert = INSERT INTO calendar (id) VALUES (2576247756) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576247766 query insert = INSERT INTO calendar (id) VALUES (2576247766) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576248369 query insert = INSERT INTO calendar (id) VALUES (2576248369) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576248388 query insert = INSERT INTO calendar (id) VALUES (2576248388) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576248660 query insert = INSERT INTO calendar (id) VALUES (2576248660) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576249706 query insert = INSERT INTO calendar (id) VALUES (2576249706) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576250254 query insert = INSERT INTO calendar (id) VALUES (2576250254) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =


Solution

  • It sounds like the type for id is too short. That value in your "duplicate entry" message (2147483647) is the maximum signed 32-bit integer value. Try using a larger size for ID.