[Mobilitydb-users] check for empty period?

Esteban Zimanyi estebanzimanyi at gmail.com
Wed Sep 7 07:57:06 PDT 2022


Dear Wendell

> I have some queries that fail with:
>
>     "ERROR:  Period cannot be empty"
>
> How can I check for this?  Is there a 'PERIOD EMPTY' that it could be checked against?  Checking for:
> " ... and upper(period(flown_path)) > lower(period(flown_path))"
> does not seem to catch the offending element.

Such an error comes as the result of an operation that does an
intersection of the time frame of two temporal values. Therefore there
is no general answer for your question, it depends on which operation
you are performing.

As a rule of thumb the overlaps (&&) operator is your friend for this
kind of operation but we must understand what we are overlapping. I
will explain this with a simple example next.

The following query does an overlap of the bounding box of the two
arguments, in this case a TBOX. The principles will be the same for
temporal points and in this case the bounding box would be an STBOX.

test=# select tfloat '{[1 at 2000-01-01,2 at 2000-01-02],[3 at 2000-01-03,
4 at 2000-01-04]}' && tfloat '[15 at 2000-01-02, 25 at 2000-01-03]';
 ?column?
----------
 f

The result is false since they overlap on the time dimension but not
on the value dimension: [1,4] does not overlap [15,25]. On the
contrary the next query returns true

test=# select tfloat '{[1 at 2000-01-01,2 at 2000-01-02],[3 at 2000-01-03,
4 at 2000-01-04]}' && tfloat '[1 at 2000-01-02, 25 at 2000-01-03]';
 ?column?
----------
 t

If we want to overlap on only one of the value/spatial or time
dimensions, then we need to extract the corresponding dimension value.
In the examples below I use the time dimension.

test=# select tfloat '{[1 at 2000-01-01,2 at 2000-01-02],[3 at 2000-01-03,
4 at 2000-01-04]}'::period && tfloat '[15 at 2000-01-02,
25 at 2000-01-03]'::period;
 ?column?
----------
 t

In the query above we are extracting the bounding period of two
arguments, and therefore the result is true since
[2000-01-01,2000-01-04] overlaps [2000-01-02, 2000-01-03].

Notice the time gap in the first argument. If we want to remove the
time gap from the computation then we can use getTime function

test=# select gettime(tfloat
'{[1 at 2000-01-01,2 at 2000-01-02],[3 at 2000-01-03, 4 at 2000-01-04]}');
                                               gettime
------------------------------------------------------------------------------------------------------
 {[2000-01-01 00:00:00+01, 2000-01-02 00:00:00+01], [2000-01-03
00:00:00+01, 2000-01-04 00:00:00+01]}
(1 row)

test=# select getTime(tfloat '[3 at 2000-01-02, 5 at 2000-01-03]');
                      gettime
----------------------------------------------------
 {[2000-01-02 00:00:00+01, 2000-01-03 00:00:00+01]}
(1 row)

Then the following query will do an overlaps of the periodset and the
period and the result will be true

test=# select gettime(tfloat
'{[1 at 2000-01-01,2 at 2000-01-02],[3 at 2000-01-03, 4 at 2000-01-04]}') &&
getTime(tfloat '[3 at 2000-01-02, 5 at 2000-01-03]');
 ?column?
----------
 t

Similarly if we take into account the inclusive/exclusive bounds, then
the following query

test=# select gettime(tfloat
'{[1 at 2000-01-01,2 at 2000-01-02),[3 at 2000-01-03, 4 at 2000-01-04]}') &&
getTime(tfloat '[3 at 2000-01-02, 5 at 2000-01-03)');
 ?column?
----------
 f

returns false since the period of the second argument is just filling
the gap of the first one as shown in the following query

test=# select gettime(tfloat
'{[1 at 2000-01-01,2 at 2000-01-02),[3 at 2000-01-03, 4 at 2000-01-04]}') +
getTime(tfloat '[3 at 2000-01-
02, 5 at 2000-01-03)');
                      ?column?
----------------------------------------------------
 {[2000-01-01 00:00:00+01, 2000-01-04 00:00:00+01]}

but the periodset and the period do not overlap.

Please let me know if this answers your question.


More information about the Mobilitydb-users mailing list