use strict; use warnings; use DBI; my $t = "pm1083865_ivo2"; # table name my $date_string ; my @hdr = (); my @val = (); while (<>) { # reading STDIN chomp; $date_string = $_; last; } while (<>) { # reading STDIN next if (/^\s*$/); chomp; if ( /^([^:]+):\s*(\d+)\s*$/ ) { push(@hdr, $1); push(@val, $2); } elsif ( /^([^:]+):\s*(\d+)\s*([^:]+):\s*(\d+)\s*$/ ) { push(@hdr, $1); push(@val, $2); push(@hdr, $3); push(@val, $4); } else { print ">>>", $_ ,"<<<\n"; die "oops - unprocessed line!\n"; } } # clean up header names for database use: for (my$i=0;$iconnect or die "no database connection - $!\n "; $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; my $arf = $dbh->selectrow_arrayref(" select count(*) from information_schema.tables where table_schema = 'public' and table_name = '$t'"); if ($arf->[0] == 0) { my $sql_create = join("\n" , "create table $t (" , " date_line timestamptz\n, " , join ("\n, ", map { $_ .= ' integer' } @hdr ) , ");" ); $dbh->do( $sql_create ); } my $sql_insert = join("\n" , "insert into $t values (" , join( ", ", map {'?'} @all_hdrs) , ");" ); my $sth = $dbh->prepare($sql_insert); my $rc = $sth->execute(@all_vals); $dbh->commit; $dbh->disconnect; #### $ echo "table pm1083865_ivo2" | psql -x | head -n 20 Timing is on. -[ RECORD 1 ]-----------------+----------------------- date_line | 2014-04-25 23:06:25+02 total_subscribers | 970260 active | 86806 dormant | 883454 pdsn_simple_ipv4 | 212 pdsn_simple_ipv6 | 0 pdsn_mobile_ip | 539792 ha_mobile_ipv6 | 0 hsgw_ipv6 | 234943 hsgw_ipv4 | 1977 hsgw_ipv4_ipv6 | 192328 pgw_pmip_ipv6 | 0 pgw_pmip_ipv4 | 0 pgw_pmip_ipv4_ipv6 | 0 pgw_gtp_ipv6 | 0 pgw_gtp_ipv4 | 0 pgw_gtp_ipv4_ipv6 | 0 sgw_gtp_ipv6 | 0 [...] etc., there are 126 columns