I am creating a database that stores arbitrary date / time ranges in PostgreSQL 9.2.4. I want to set a restriction on this database, which causes date / time ranges to be non-overlapping and non-contiguous (since two adjacent ranges can be expressed as one continuous range).
For this, I use the EXCLUDE constraint with the GiST index. Here is the limitation that I have:
ADD CONSTRAINT overlap_exclude EXCLUDE USING GIST ( box( point ( extract(EPOCH FROM "from") - 1, extract(EPOCH FROM "from") - 1 ), point ( extract(EPOCH FROM "to"), extract(EPOCH FROM "to") ) ) WITH && );
The from and to columns are TIMESTAMP WITHOUT TIME ZONE and are the date / time stored in UTC (I convert to UTC before inserting data into these columns in my application and I have the time zone of my "UTC" database set to postgresql. conf).
The problem that I think may have, however, is that this restriction makes the (wrong) assumption that the time intervals are less than one second.
It is worth noting that for the specific data that I store, I only need a second resolution. However, I feel that I still need to deal with this, because the SQL types timestamp and timestamptz have a higher resolution than one second.
My question is: is there a problem with simply accepting the second resolution, since my whole application needs (or wants), or, if there is, how can I change this restriction to deal with fractions in a second reliable way?
sql datetime postgresql constraints exclusion-constraint
Cmdrmoozy
source share