my @c;
+ my $timestamp =
+ exists $h->{timestamp} ? $h->{timestamp} :
+ exists $h->{start} ? $h->{start} :
+ warn "no timestamp partitioning on $table";
+
+ my $create_table;
+ if ( $timestamp ) {
+ $timestamp =~ s/^(\d{4})-(\d{2})-(\d{2}).*$/$1_$2_$3/;
+ my $part = $table . '_' . $timestamp;
+ $create_table = qq{
+ create table $part () inherits ($table) ;
+ };
+ $table = $part;
+ warn "# using partition $table";
+ }
+
if ( my $cols = $self->redis->get("pg.$table") ) {
@c = split(/\s+/,$cols);
} else {
my $sth = $self->dbh->prepare( "select * from $table limit 1" );
- $sth->execute;
+ eval { $sth->execute; };
+ if ( $@ ) {
+ warn "ERROR $@\n# try $create_table\n";
+ $self->dbh->do( $create_table );
+ $sth->execute;
+ }
+
@c = @{ $sth->{NAME_lc} };
$self->redis->set( "pg.$table" => join(' ',@c) );
$self->redis->expire( "pg.$table" => 15 * 60 ); # refresh every 15 min