Skip to content

Commit dcf4955

Browse files
committed
IdoPgsqlConnection#FieldToEscapedString(): write out of range time as NULL
just like in MySQL. Except MySQL's FROM_UNIXTIME() does that implicitly. In contrast, Postgres' TO_TIMESTAMP() fails, so WE have to handle it.
1 parent a48e978 commit dcf4955

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/db_ido_pgsql/idopgsqlconnection.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,17 @@ bool IdoPgsqlConnection::FieldToEscapedString(const String& key, const Value& va
701701
*result = static_cast<long>(dbrefcol);
702702
} else if (DbValue::IsTimestamp(value)) {
703703
double ts = rawvalue;
704+
705+
// PostgreSQL timestamp limits. Not the exact ones, but with "better safe than sorry" buffers
706+
// not to worry about time zones, floating point arithmetic details and the precise numbers themselves.
707+
// The buffers were chosen so that the resulting numbers are easy to write and read.
708+
if (ts < -2e11 || ts > 9e12) {
709+
// NULL is even more eye-catching than the very low/high numbers themselves
710+
// and consistent with the behavior of FROM_UNIXTIME() in MySQL.
711+
*result = "NULL";
712+
return true;
713+
}
714+
704715
std::ostringstream msgbuf;
705716
msgbuf << "TO_TIMESTAMP(" << std::fixed << std::setprecision(0) << ts << ") AT TIME ZONE 'UTC'";
706717
*result = Value(msgbuf.str());

0 commit comments

Comments
 (0)