+ r->postgres_epoch = calendar_gregorian_to_offset (
+ 2000, 1, 1, settings_get_fmt_settings (), NULL);
+
+ {
+ const int enc = PQclientEncoding (r->conn);
+
+ /* According to section 22.2 of the Postgresql manual
+ a value of zero (SQL_ASCII) indicates
+ "a declaration of ignorance about the encoding".
+ Accordingly, we use the default encoding
+ if we find this value.
+ */
+ encoding = enc ? pg_encoding_to_char (enc) : get_default_encoding ();
+
+ /* Create the dictionary and populate it */
+ *dict = r->dict = dict_create (encoding);
+ }
+
+ const int version = PQserverVersion (r->conn);
+ /*
+ Versions before 9.1 don't have the REPEATABLE READ isolation level.
+ However according to <a12321aabb@gmail.com> if the server is in the
+ "hot standby" mode then SERIALIZABLE won't work.
+ */
+ char *query = xasprintf (
+ "BEGIN READ ONLY ISOLATION LEVEL %s; "
+ "DECLARE pspp BINARY CURSOR FOR %s",
+ (version < 90100) ? "SERIALIZABLE" : "REPEATABLE READ",
+ info->sql);
+ qres = PQexec (r->conn, query);
+ free (query);
+
+ if (PQresultStatus (qres) != PGRES_COMMAND_OK)
+ {
+ msg (ME, _("Error from psql source: %s."),
+ PQresultErrorMessage (qres));
+ goto error;
+ }