Skip to content

Commit 8cc18b1

Browse files
committed
psql-srv: Add integer_datetimes to PG ready message
A long, long time ago, in a galaxy far, far away, Postgres internally represented `timestamp` and `interval` types as `doubles`. Around version 8.4 (July 2009), this was changed to an `integer` for various precision correctness issues. As a result, Postgres would, and still does to this day, return a `ParameterStatus` to clients on a new connection to declare if the server is treating `timestamp` and `interval` types as `doubles`. This status is named `integer_datetimes` and, since Postgres v10, always returns `on` (meaning it's always returning 8-byte integers). This distinction primarily matters then the server is asked to return values in the binary format; text format just returns a string representation of the value. Some Postgres drivers still expect to see that `integer_datetimes` parameter, and if they do not see it, will assume the server will represent `timestamp` and `interval` types as `doubles`. This is what happens with the PGJDBC driver. When the client asks for a `timestamp` column, to be returned in binary format - which is what pgjdbc does for named prepared statements - the connection will still check its state to see if the `timestamp`'s 8-bytes should be interpreted as a double or integer value (a `long`). This CL adds an extra `ParameterStatus` in the new connection ready message for the `integer_datetimes` parameter. Fixes: #1365 Release-Note-Core: Fix bug affecting pgjdbc clients where binary-formatted timestamp columns in result sets are interpreted incorrectly. Change-Id: Ia783b861b9dd8923e57a235cf097548c468648aa Reviewed-on: https://gerrit.readyset.name/c/readyset/+/7936 Tested-by: Buildkite CI Reviewed-by: Johnathan Davis <jcd@readyset.io>
1 parent 44a1ed0 commit 8cc18b1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

psql-srv/src/protocol.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ impl Protocol {
223223
parameter_name: "standard_conforming_strings".to_owned(),
224224
parameter_value: "on".to_owned(),
225225
},
226+
BackendMessage::ParameterStatus {
227+
parameter_name: "integer_datetimes".to_owned(),
228+
parameter_value: "on".to_owned(),
229+
},
226230
BackendMessage::ParameterStatus {
227231
parameter_name: "server_version".to_owned(),
228232
parameter_value: version,
@@ -1382,6 +1386,7 @@ mod tests {
13821386
BackendMessage::ParameterStatus { .. },
13831387
BackendMessage::ParameterStatus { .. },
13841388
BackendMessage::ParameterStatus { .. },
1389+
BackendMessage::ParameterStatus { .. },
13851390
BackendMessage::ReadyForQuery {
13861391
status: READY_FOR_QUERY_IDLE
13871392
}

0 commit comments

Comments
 (0)