PostgreSQL, Perl, DBD and the Insert command with "TO_TIMESTAMP" -
i'm programming script queries devices , writes data postgresql database.
the data includes date formatted 31.12.2015 13:45:00. database uses datetype "german" , column of type timestamp without timezone.
i error message
dbd::pg::st execute failed: error: invalid input syntax type timestamp: "to_timestamp('19.06.2015 11:24:20','dd.mm.yyyy hh24:mi:ss')::timestamp without time zone" @ temp_alcp2e_db.pl line 80, line 289.
i'm using code, $date_db has date value:
$date_db = 'to_timestamp(\'' . $date_db . '\',\'dd.mm.yyyy hh24:mi:ss\')::timestamp without time zone'; $stmt = $dbh->prepare("insert rifutemp (\"user_link_id\", \"ip\", \"datum\", \"temperature\") values (?, ?, ?, ?)"); $stmt->execute($key_bgtr, $key_ip, $date_db, $temperatur) or die $dbi::errstr; hopefully, can show me did wrong.
the function can (and must) part of prepared statement.
re-write code follows:
$stmt =$dbh->prepare(q{ insert rifutemp ("user_link_id","ip","datum","temperature") values (?, ?, to_timestamp(?, 'dd.mm.yyyy hh24:mi:ss')::timestamp without time zone, ?) }); $stmt->execute($key_bgtr,$key_ip,$date_db,$temperatur) or die $dbi::errstr;
Comments
Post a Comment