From df1118b4e091dfd251cc4414a4fca8cc9e764648 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 18 Oct 2024 18:30:38 +0200 Subject: [PATCH] SQL/PostgreSQL: fix comment for formatting QDateTime The comment to convert a QDateTime to a PostgreSQL compatible string was outdated. Adjust it to the current state and make clear that the PostgreSQL documentation is unclear here. Task-number: QTBUG-129983 Change-Id: I46e45082f2154881ab34278c5e9887cb2274dd64 Reviewed-by: Edward Welbourne (cherry picked from commit d6a7e51fa36c51a39c609ff0b2cd8bc10bd01e86) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 7cbe572d6e5..95c52d394ed 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -1454,9 +1454,9 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const case QMetaType::QDateTime: { const auto dt = field.value().toDateTime(); if (dt.isValid()) { - // we force the value to be considered with a timezone information, and we force it to be UTC - // this is safe since postgresql stores only the UTC value and not the timezone offset (only used - // while parsing), so we have correct behavior in both case of with timezone and without tz + // even though the documentation (https://www.postgresql.org/docs/current/datatype-datetime.html) + // states that any time zone indication for 'timestamp without tz' columns will be ignored, + // it is stored as the correct utc timestamp - so we can pass the utc offset here r = QStringLiteral("TIMESTAMP WITH TIME ZONE ") + u'\'' + dt.toOffsetFromUtc(dt.offsetFromUtc()).toString(Qt::ISODateWithMs) + u'\''; } else {