Unstable timestamp binary representation?

Started by Shachar Shemeshalmost 21 years ago3 messages
#1Shachar Shemesh
psql@shemesh.biz

Hi all,

In the OLE DB code there is code for parsing timestamps received from
the server. This code behaves erratically. Upon further examination, I
found the following piece of code in Postgresql's "timestamp2tm":

#ifdef HAVE_INT64_TIMESTAMP
dt -= CTimeZone * INT64CONST(1000000);
#else
dt -= CTimeZone;
#endif

In other words, it seems that I, as a client, needs to guess whether
postgres was compiled with or without "HAVE_INT64_TIMESTAMP". If it was,
what I am getting is a big-endian int64. If it was not, this is a double
that needs to be multiplied by 1000000.

In my tests, Potgresql 8 running on Windows uses "double", while
Postgresql 7.4 running on Debian Linux SID uses int64. Is there any way
I can remotely detect which is it?

Reading from the actual code, it seems each instance of postgres just
assumes that it was encoded in the same format as it was compiled with,
not stopping to ask what the other side was compiled with. Is this a bug
in postgres as well?

Shachar

--
Shachar Shemesh
Lingnu Open Source Consulting ltd.
Have you backed up today's work? http://www.lingnu.com/backup.html

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Shachar Shemesh (#1)
Re: Unstable timestamp binary representation?

Shachar Shemesh <psql@shemesh.biz> writes:

In other words, it seems that I, as a client, needs to guess whether
postgres was compiled with or without "HAVE_INT64_TIMESTAMP".

No, you need to inquire of the value of the "integer_datetimes"
parameter. (At least as of 8.0, this is provided "for free" during
connection startup, so you don't even need an extra network round
trip to find it out.)

Reading from the actual code, it seems each instance of postgres just
assumes that it was encoded in the same format as it was compiled with,

No, it checks. See pg_control.

regards, tom lane

#3Shachar Shemesh
psql@shemesh.biz
In reply to: Tom Lane (#2)
Re: Unstable timestamp binary representation?

Tom Lane wrote:

Shachar Shemesh <psql@shemesh.biz> writes:

In other words, it seems that I, as a client, needs to guess whether
postgres was compiled with or without "HAVE_INT64_TIMESTAMP".

No, you need to inquire of the value of the "integer_datetimes"
parameter. (At least as of 8.0, this is provided "for free" during
connection startup, so you don't even need an extra network round
trip to find it out.)

Hmm. So I need to call "|PQparameterStatus" with "|integer_datetimes".
If I get "TRUE", treat as integer, if I get "FALSE", treat as double.
What happens if I get NULL? The docs seem to suggest that this is what
will happen for 7.4 back end, and the FALSE is the default. My
experience shows, however, that at least 7.4 for Debian Sid should be true.

No, it checks. See pg_control.

Not what I have seen from the code, but I will take your word for it.

regards, tom lane

Shachar

--
Shachar Shemesh
Lingnu Open Source Consulting ltd.
Have you backed up today's work? http://www.lingnu.com/backup.html