in reply to Re: Pull data from two tables, insert into new table?
in thread Pull data from two tables, insert into new table?

Well, the two calendar tables I'll be pulling from are Oracle based, and the table I'll be writing to is MySQL.

I'm not sure I understand your second question, but if you are asking whether the time period would be from now until the last date in the exception table, the answer is yes--this script would run every night on the crontab and pick up any changes made to the exception table that day.

  • Comment on Re^2: Pull data from two tables, insert into new table?

Replies are listed 'Best First'.
Re^3: Pull data from two tables, insert into new table?
by poj (Abbot) on Feb 16, 2016 at 18:43 UTC

    My 2nd question really was 'How far into the future do you want the dates in the mysql table to go '.

    It could get more complicated if you want to detect changes to the 2 oracle tables. Assuming the record count is in the hundreds, it might be simpler just to delete all future records and regenerate the table each night.

    As a starter idea, here is a test script that generates the records you would need to insert.

    #!perl use strict; use DBI; use Time::Piece; use Time::Seconds; my %regular = ( Mon => ['08:00','17:00'], Tue => ['08:00','17:00'], Wed => ['08:00','17:00'], Thu => ['08:00','17:00'], Fri => ['08:00','17:00'], Sat => ['08:00','12:00'], Sun => ['00:00','00:00'], ); my %except = ( '2016-05-30' => ['00:00','00:00'], '2016-07-04' => ['00:00','00:00'], '2016-09-05' => ['00:00','00:00'], '2016-10-10' => ['00:00','00:00'], '2016-11-08' => ['00:00','00:00'], '2016-11-11' => ['00:00','00:00'], '2016-11-24' => ['00:00','00:00'], '2016-12-26' => ['00:00','00:00'], ); my $t = localtime; my $end_date = '2016-12-31'; open OUT,'>','all_dates.csv' or die "$!"; my $id = 1; while ($t->ymd le $end_date){ my $ymd = $t->ymd; my $w = $t->wdayname; my $open = $except{$ymd}[0] || $regular{$w}[0]; my $close = $except{$ymd}[1] || $regular{$w}[1]; my $is_closed = ($open eq '00:00') ? 1 : 0; print OUT "$id,$ymd,$w,$open,$close,$is_closed\n"; $t += ONE_DAY; ++$id; } close OUT;
    poj

      Thank you, poj.

      Yes, I think that is right--the table should be rewritten each night. We generally run our exception hours by the semester, so it can contain up to three months' worth. The beginning and end of the semesters can be dicey though, a lot of changes going on.

      I could also see the value, however, of keeping previous exception dates stored, so that the "analog" calendar the combined table populates can be turned back, say, to last year to see what hours we were keeping then--for statistical purposes or whatever.

      Thanks again--I'm going to start working with this and see what I come up with!

      HC

        Ok, the major complication I see is if you implement a change to the regular hours in the future. You would need to add valid_from_date ,valid_to_date fields to that table, or do they have them already ?

        poj