Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Finding missing sequence records in DB table

by gmax (Abbot)
on Aug 05, 2003 at 11:41 UTC ( #280946=note: print w/replies, xml ) Need Help??


in reply to DBD::ODBC won't read past a certain record

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

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

Replies are listed 'Best First'.
Re: Finding missing sequence records in DB table
by Groll (Acolyte) on Aug 06, 2003 at 04:50 UTC
    Sorry, but this is not the problem. As I said, there are over 1,006,000 records (all of which I can see via Access, which uses the same ODBC DSN, and Enterprise Manager remotely).
    Many thanks for your input though. My other replies have further details following on from other responses.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://280946]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-12-08 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?