Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

If I understand correctly, the gist of what you are asking is "how can I find which records are missing from a given sequence?"

If this is true, one method to find out is to use an auxiliary table containing all the sequence numbers, and perform a LEFT JOIN to your table.

First, create such table and fill it with the values from 1 to the maximum record number you want to consider. What Corion said about maximum record number and unique numbers in Transaction are still valid and you should check them. However, assuming that TransactionID is unique, this method will find the missing rows very fast.

#!/usr/bin/perl -w use strict; use DBI; my $dbh = DBI->connect("dbi:driver:database", "user","password",{RaiseError=>1}) or die; $dbh->do(qq{ create table sequence (id int not null primary key)) }); my $sth = $dbh->prepare(qq{ insert into sequence values (?) }); $dbh->{autocommit} =0; $dbh->begin; for ( 1.. 1_200_000) { $sth->execute($_); if (($_ % 1000) == 0) { $dbh->commit; $dbh->begin; } } $dbh->commit; my $min = 968000; my $max = 1029829; my $sequence_query = qq{ SELECT a.id FROM sequence a LEFT JOIN Transaction b ON (a.id=b.TranstactionID) WHERE a.id BETWEEN $min AND $max AND b.TranstactionID IS NULL }; $sth = $dbh->prepare($sequence_query); $sth->execute(); while (my ($row) = $sth->fetchrow_array) { print "$row is missing \n"; } $dbh->disconnect();

HTH

 _  _ _  _  
(_|| | |(_|><
 _|   

In reply to Finding missing sequence records in DB table by gmax
in thread DBD::ODBC won't read past a certain record by Groll

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-20 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found