Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Db table to non-alike db table copying

by g0n (Priest)
on Feb 06, 2006 at 08:37 UTC ( [id://528172]=note: print w/replies, xml ) Need Help??


in reply to Db table to non-alike db table copying

Alternatively, at risk of pimping my own module, Data::Sync is designed to do this sort of operation. Here's an example:

my $h=Data::Sync->new(); $h->source($sourcedbihandle,"select * from source"); $h->target($targetdbihandle,{index=>"MYPRIMKEY", hashattributes=>[field1,field2]}); $h->mappings(field1=>'targetfield1',field2=>'targetfield2'); $h->transforms(targetfield1=>"s/(\w)+\s(\w+)/$2 $1/", targetfield2=>"lowercase"); $h->run;
That would:
read from $sourcedbihandle all records that match the query
Remap the source field names to the target field names
Transform the data in field1 with the regex, and field2 lowercase
Write all records that have changed since the last run.

Deletion isn't supported in v0.06 (on CPAN), but the next version has deletion support; I'm currently trying to up the test coverage, but if you want to /msg me I can send you an early copy.

Update: Just to clarify - writing only records that have changed since the last run is based on hashing a list of attributes. The 'hashattributes' parameter to target() contains a list of the attributes you want to hash.

--------------------------------------------------------------

"If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."
John Brunner, "The Shockwave Rider".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found