From 0a1424bcab7d7e8d4d99d5e317fbe31fefd5de8f Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sat, 18 Aug 2012 18:12:43 +0200 Subject: [PATCH] postgresql plugin: Format time in ISO 8601 format when writing data. This way, the value may directly be used as a timestamp value in PostgreSQL. --- src/postgresql.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/postgresql.c b/src/postgresql.c index d6e04a85..7bc450ea 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -658,7 +658,7 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl, { c_psql_database_t *db; - char time_str[1024]; + char time_str[32]; char values_name_str[1024]; char values_str[1024]; @@ -676,8 +676,10 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl, assert (db->database != NULL); assert (db->writers != NULL); - ssnprintf (time_str, sizeof (time_str), - "%f", CDTIME_T_TO_DOUBLE (vl->time)); + if (cdtime_to_iso8601 (time_str, sizeof (time_str), vl->time) == 0) { + log_err ("c_psql_write: Failed to convert time to ISO 8601 format"); + return -1; + } if (values_name_to_sqlarray (ds, values_name_str, sizeof (values_name_str)) == NULL) -- 2.30.2