6.8.3.3 Using INTERVAL Literals in PGQL Queries
You can use INTERVAL literals in PGQL
queries to add or subtract intervals to or from PGQL temporal data types
respectively.
An INTERVAL type is a
period of time, which consists of the keyword "INTERVAL" followed
by a numeral and a temporal unit. For example, INTERVAL '1'
DAY.
The following table shows the valid temporal units
that are supported in INTERVAL values:
Table 6-4 Valid values for fields in
INTERVAL values
| Keyword | Supported Valid Values |
|---|---|
YEAR |
Unconstrained except by <interval leading field precision> |
MONTH |
Months (within years) (0-11) |
DAY |
Unconstrained except by <interval leading field precision> |
HOUR |
Hours (within days) (0-23) |
MINUTE |
Minutes (within hours) (0-59) |
SECOND |
Seconds (within minutes) (0-59.999...) |
The following INTERVAL operations are supported
on a temporal data type:
TEMPORAL TYPE + INTERVALINTERVAL + TEMPORAL TYPETEMPORAL TYPE - INTERVAL
For example, the following PGQL query retrieves persons where
n.birthdate + INTERVAL '20' YEAR > TIMESTAMP '2000-01-01
00:00:00':
opg4j> graph.queryPgql("SELECT n.name, n.birthdate FROM MATCH (n:Person) WHERE n.birthdate + INTERVAL '20' YEAR > TIMESTAMP '2000-01-01 00:00:00'").print()graph.queryPgql("SELECT n.name, n.birthdate FROM MATCH (n:Person) WHERE n.birthdate + INTERVAL '20' YEAR > TIMESTAMP '2000-01-01 00:00:00'").print();graph.query_pgql("SELECT n.name, n.birthdate FROM MATCH (n:Person) WHERE n.birthdate + INTERVAL '20' YEAR > TIMESTAMP '2000-01-01 00:00:00'").print()On execution, the query output is as shown:
+--------------------------+
| name | birthdate |
+--------------------------+
| Mary | 1982-09-25T00:00 |
| Alice | 1987-02-01T00:00 |
+--------------------------+
Parent topic: PGQL Features Supported in the Graph Server (PGX)