Moving Data from one table to another table

From: Chris Lyon (cslyon_at_netsvcs.com)
Date: 12/28/04

  • Next message: Chris Devers: "Re: Moving Data from one table to another table"
    To: <beginners@perl.org>
    Date: Tue, 28 Dec 2004 10:11:35 -0800
    
    

    Maybe this is a little OT but since I am a beginner @ perl, I thought that I
    would post it!

     

    So, I am trying to move data from one sql table to another table called
    logs_archive. It seems that I am running into some problems with memory as I
    am moving this much data from one table to another. This is just syslog data
    but we need to archive it in some way. Can anybody give any advice? Code is
    below.

     

     

     

     

    $sth = $dbh->prepare( "select * from logs where ( timestamp <=
    '$start_date$start_time' )" );

    $sth->execute();

     

    while ( my $ref = $sth->fetchrow_hashref() ) {

                $msg_field = $ref->{'msg'};

                if ( $msg_field =~ /\'/ ) {

                            $msg_field =~ s/\'/\\'/g;

                }

                $string = "INSERT INTO logs_archive ( timestamp, host, facility,
    priority, level, tag, date, time, program, msg ) VALUES (
    '$ref->{'timestamp'}', '$ref->{'host'}', '$ref->{'facility'}',
    '$ref->{'priority'}', '$ref->{'level'}', '$ref->{'tag'}', '$ref->{'date'}',
    '$ref->{'time'}', '$ref->{'program'}', '$msg_field' )";

                $dbh->do( $string );

    }

     

    $string_delete = "delete from logs where ( timestamp <=
    '$start_date$start_time' )";


  • Next message: Chris Devers: "Re: Moving Data from one table to another table"

    Relevant Pages

    • Re: Beginner needs help with script :)
      ... >> come to these forums and post a question about perl AT ALL? ... Yes what he was saying was that the subject matter in my subject line, ... And I put it to him and you that my subject line simplysays I am a beginner ... is very honest and humble I think. ...
      (comp.lang.perl.misc)
    • Re: Need RE. New to Perl
      ... Now I need to use Perl and could really ... >> I am writing a function in the Postgresql database using Perl ... >> Tag: None ... > use strict; ...
      (perl.beginners)
    • Re: Perl beginner seeks help
      ... Mr. low level newb of stupidity;) wrote: ... learner of Perl. ... I guess you could call me a beginner. ...
      (perl.beginners)
    • Re: date format
      ... I'm not a beginner and I found this example rather obscure and hard to ... Perl needn't look that much like line noise IMO. ... but the content of that array is not univocal here anyway) ...
      (comp.lang.perl.misc)
    • Re: Ada performance (was No call for Ada )
      ... >> Your mathematics seems seriously flawed. ... You are stating that Perl has a speed closer to a language taking ... GNAT, an Ada compiler, is a front end to GCC and so should use the ... > MSG ...
      (comp.lang.c)