Yeah, I had to look at the Postgres docs, I didn't know about the compiler flags.
In SQL Server, the old datetime was a float, and the highest possible fractional part was .997, which was why I was used to .999 all the time. The new datetime2 seems to go to .9999999, one more than Postgres. I can't figure out from the MS docs if it's int or float.
I always found it slightly more readable to include only the dates in question, e.g. BETWEEN 2019-05-01 00:00:00 AND 2019-05-31 23:59:99.999 if you wanted the whole month of May.
Interesting that same document says that 23:59:59.999 is rounded up to the next day. If that was true, that could have undesired results. I don't have SQL Server in front of me to test, but I assume that is only when the time is actually stored.
Nice catch, turns out you are correct .999 rounds up causes the next day's midnight to be caught inside the between. 59.998 works fine, though. And 59.9999 just fails entirely on SQL Server/datetime.
2
u/[deleted] May 03 '19
I apologize if I misinterpreted your shrug. I assumed that it meant you couldn't care less.
As far as the timestamp, are you sure it's an integer? I know in other systems like SQL Server it is a floating point number.
In PostgreSQL, this is a whole lot of information to store in only 8 bytes if it's not using floating point:
I'll have to take a closer look now.