From: Sebastian Harl Date: Sat, 18 Aug 2012 16:12:43 +0000 (+0200) Subject: postgresql plugin: Format time in ISO 8601 format when writing data. X-Git-Tag: collectd-5.2.0~13^2~22 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0a1424bcab7d7e8d4d99d5e317fbe31fefd5de8f;p=collectd.git 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. --- 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)