LiTinOveWeedle has asked for the wisdom of the Perl Monks concerning the following question:
1. records existing only in first table
2. records existing only in second table
3. records with identical primary keys, but with different content.
4. record which are totaly identicals.
To do that I am using DBI::Oracle module and ->selectall_hashref() method to fetch whole content of both tables to two hash data structures. Than I have simple procedure to compare both hashes and as result I get three hashes (see points 1-3, I don't take care about identical record - point 4) This works good for now. I am using something like this:
foreach $key ( keys %{$hash1} ) { if ( exists( $hash2->{$key} ) ) { if ( not compare( $hash1->{$key}, $hash2->{$key} ) ) { $hash3->{$key} = $hash1->{$key}; } delete( $hash1->{$key} ); delete( $hash2->{$key} ); } }
where $hash1 and $hash2 are references to input tables and output are hash1(see point 1.), hash2(see point 2.) and hash3(see point 3.)
Problem is, that in this time tables contains about hundreds of records. Now we are going to store about 10.000 records in tables!!! Because I am reading whole table into perl variable (into the memory):
1. I want to know, if perl can handle so big data structure or is this just HW sizing problem?
2. Is there more efficient way to do this comparision in perl?
3. Is there more efficient way how to compare two tables with same results directly in SQL?
->selectall_hashref() method return hash of arrays, where each array is one row in SQL table and hash key is in my example sql primary key. Table has about 20 collumns.
Hope that the code I wrote bellow is good. I tried to memorized it, but my brain work worse than sql database :-). Thank you for help brothers.
Regards LTOW
Li Tin O've Weedle
mad Tsort's philosopher
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SQL vs Perl table comparing
by CubicSpline (Friar) on Nov 07, 2002 at 18:46 UTC | |
|
Re: SQL vs Perl table comparing
by FamousLongAgo (Friar) on Nov 07, 2002 at 18:42 UTC | |
|
Re: SQL vs Perl table comparing
by grantm (Parson) on Nov 07, 2002 at 23:31 UTC | |
|
Re: SQL vs Perl table comparing
by rdfield (Priest) on Nov 08, 2002 at 10:23 UTC | |
|
Re: SQL vs Perl table comparing
by Anonymous Monk on Jul 11, 2013 at 10:52 UTC | |
by runrig (Abbot) on Jul 11, 2013 at 16:39 UTC | |
by roboticus (Chancellor) on Jul 11, 2013 at 11:46 UTC | |
by runrig (Abbot) on Jul 11, 2013 at 16:41 UTC |