Commit 52ad1e65 authored by Alexander Korotkov's avatar Alexander Korotkov

Refactor jsonpath's compareDatetime()

This commit refactors come ridiculous coding in compareDatetime().  Also, it
provides correct cross-datatype comparison even when one of values overflows
during cast.  That eliminates dilemma on whether we should suppress overflow
errors during cast.

Reported-by: Tom Lane
Discussion: https://postgr.es/m/32308.1569455803%40sss.pgh.pa.us
Discussion: https://postgr.es/m/a5629d0c-8162-7559-16aa-0c8390d6ba5f%40postgrespro.ru
Author: Nikita Glukhov, Alexander Korotkov
parent a6888fde
...@@ -554,11 +554,12 @@ date_mii(PG_FUNCTION_ARGS) ...@@ -554,11 +554,12 @@ date_mii(PG_FUNCTION_ARGS)
/* /*
* Promote date to timestamp. * Promote date to timestamp.
* *
* If 'have_error' is NULL, then errors are thrown, else '*have_error' is set * On overflow error is thrown if 'overflow' is NULL. Otherwise, '*overflow'
* and zero is returned. * is set to -1 (+1) when result value exceed lower (upper) boundary and zero
* returned.
*/ */
Timestamp Timestamp
date2timestamp_opt_error(DateADT dateVal, bool *have_error) date2timestamp_opt_overflow(DateADT dateVal, int *overflow)
{ {
Timestamp result; Timestamp result;
...@@ -575,9 +576,9 @@ date2timestamp_opt_error(DateADT dateVal, bool *have_error) ...@@ -575,9 +576,9 @@ date2timestamp_opt_error(DateADT dateVal, bool *have_error)
*/ */
if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE)) if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
{ {
if (have_error) if (overflow)
{ {
*have_error = true; *overflow = 1;
return (Timestamp) 0; return (Timestamp) 0;
} }
else else
...@@ -596,22 +597,23 @@ date2timestamp_opt_error(DateADT dateVal, bool *have_error) ...@@ -596,22 +597,23 @@ date2timestamp_opt_error(DateADT dateVal, bool *have_error)
} }
/* /*
* Single-argument version of date2timestamp_opt_error(). * Single-argument version of date2timestamp_opt_overflow().
*/ */
static TimestampTz static TimestampTz
date2timestamp(DateADT dateVal) date2timestamp(DateADT dateVal)
{ {
return date2timestamp_opt_error(dateVal, NULL); return date2timestamp_opt_overflow(dateVal, NULL);
} }
/* /*
* Promote date to timestamp with time zone. * Promote date to timestamp with time zone.
* *
* If 'have_error' is NULL, then errors are thrown, else '*have_error' is set * On overflow error is thrown if 'overflow' is NULL. Otherwise, '*overflow'
* and zero is returned. * is set to -1 (+1) when result value exceed lower (upper) boundary and zero
* returned.
*/ */
TimestampTz TimestampTz
date2timestamptz_opt_error(DateADT dateVal, bool *have_error) date2timestamptz_opt_overflow(DateADT dateVal, int *overflow)
{ {
TimestampTz result; TimestampTz result;
struct pg_tm tt, struct pg_tm tt,
...@@ -631,9 +633,9 @@ date2timestamptz_opt_error(DateADT dateVal, bool *have_error) ...@@ -631,9 +633,9 @@ date2timestamptz_opt_error(DateADT dateVal, bool *have_error)
*/ */
if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE)) if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
{ {
if (have_error) if (overflow)
{ {
*have_error = true; *overflow = 1;
return (TimestampTz) 0; return (TimestampTz) 0;
} }
else else
...@@ -659,9 +661,15 @@ date2timestamptz_opt_error(DateADT dateVal, bool *have_error) ...@@ -659,9 +661,15 @@ date2timestamptz_opt_error(DateADT dateVal, bool *have_error)
*/ */
if (!IS_VALID_TIMESTAMP(result)) if (!IS_VALID_TIMESTAMP(result))
{ {
if (have_error) if (overflow)
{ {
*have_error = true; if (result < MIN_TIMESTAMP)
*overflow = -1;
else
{
Assert(result >= END_TIMESTAMP);
*overflow = 1;
}
return (TimestampTz) 0; return (TimestampTz) 0;
} }
else else
...@@ -677,12 +685,12 @@ date2timestamptz_opt_error(DateADT dateVal, bool *have_error) ...@@ -677,12 +685,12 @@ date2timestamptz_opt_error(DateADT dateVal, bool *have_error)
} }
/* /*
* Single-argument version of date2timestamptz_opt_error(). * Single-argument version of date2timestamptz_opt_overflow().
*/ */
static TimestampTz static TimestampTz
date2timestamptz(DateADT dateVal) date2timestamptz(DateADT dateVal)
{ {
return date2timestamptz_opt_error(dateVal, NULL); return date2timestamptz_opt_overflow(dateVal, NULL);
} }
/* /*
......
This diff is collapsed.
...@@ -5190,12 +5190,12 @@ timestamp_timestamptz(PG_FUNCTION_ARGS) ...@@ -5190,12 +5190,12 @@ timestamp_timestamptz(PG_FUNCTION_ARGS)
/* /*
* Convert timestamp to timestamp with time zone. * Convert timestamp to timestamp with time zone.
* *
* If 'have_error' is NULL, then errors are thrown, else '*have_error' is set * On overflow error is thrown if 'overflow' is NULL. Otherwise, '*overflow'
* and zero is returned. * is set to -1 (+1) when result value exceed lower (upper) boundary and zero
* returned.
*/ */
TimestampTz TimestampTz
timestamp2timestamptz_opt_error(Timestamp timestamp, bool *have_error) timestamp2timestamptz_opt_overflow(Timestamp timestamp, int *overflow)
{ {
TimestampTz result; TimestampTz result;
struct pg_tm tt, struct pg_tm tt,
...@@ -5216,30 +5216,33 @@ timestamp2timestamptz_opt_error(Timestamp timestamp, bool *have_error) ...@@ -5216,30 +5216,33 @@ timestamp2timestamptz_opt_error(Timestamp timestamp, bool *have_error)
{ {
return result; return result;
} }
else if (have_error) else if (overflow)
{ {
*have_error = true; if (result < MIN_TIMESTAMP)
*overflow = -1;
else
{
Assert(result >= END_TIMESTAMP);
*overflow = 1;
}
return (TimestampTz) 0; return (TimestampTz) 0;
} }
} }
if (have_error) ereport(ERROR,
*have_error = true; (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
else errmsg("timestamp out of range")));
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
return 0; return 0;
} }
/* /*
* Single-argument version of timestamp2timestamptz_opt_error(). * Single-argument version of timestamp2timestamptz_opt_overflow().
*/ */
static TimestampTz static TimestampTz
timestamp2timestamptz(Timestamp timestamp) timestamp2timestamptz(Timestamp timestamp)
{ {
return timestamp2timestamptz_opt_error(timestamp, NULL); return timestamp2timestamptz_opt_overflow(timestamp, NULL);
} }
/* timestamptz_timestamp() /* timestamptz_timestamp()
......
...@@ -70,8 +70,8 @@ typedef struct ...@@ -70,8 +70,8 @@ typedef struct
/* date.c */ /* date.c */
extern int32 anytime_typmod_check(bool istz, int32 typmod); extern int32 anytime_typmod_check(bool istz, int32 typmod);
extern double date2timestamp_no_overflow(DateADT dateVal); extern double date2timestamp_no_overflow(DateADT dateVal);
extern Timestamp date2timestamp_opt_error(DateADT dateVal, bool *have_error); extern Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow);
extern TimestampTz date2timestamptz_opt_error(DateADT dateVal, bool *have_error); extern TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow);
extern void EncodeSpecialDate(DateADT dt, char *str); extern void EncodeSpecialDate(DateADT dt, char *str);
extern DateADT GetSQLCurrentDate(void); extern DateADT GetSQLCurrentDate(void);
extern TimeTzADT *GetSQLCurrentTime(int32 typmod); extern TimeTzADT *GetSQLCurrentTime(int32 typmod);
......
...@@ -97,8 +97,8 @@ extern int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2); ...@@ -97,8 +97,8 @@ extern int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2);
/* timestamp comparison works for timestamptz also */ /* timestamp comparison works for timestamptz also */
#define timestamptz_cmp_internal(dt1,dt2) timestamp_cmp_internal(dt1, dt2) #define timestamptz_cmp_internal(dt1,dt2) timestamp_cmp_internal(dt1, dt2)
extern TimestampTz timestamp2timestamptz_opt_error(Timestamp timestamp, extern TimestampTz timestamp2timestamptz_opt_overflow(Timestamp timestamp,
bool *have_error); int *overflow);
extern int isoweek2j(int year, int week); extern int isoweek2j(int year, int week);
extern void isoweek2date(int woy, int *year, int *mon, int *mday); extern void isoweek2date(int woy, int *year, int *mon, int *mday);
......
...@@ -1949,17 +1949,17 @@ select jsonb_path_query( ...@@ -1949,17 +1949,17 @@ select jsonb_path_query(
'["2017-03-10", "2017-03-11", "2017-03-09", "12:34:56", "01:02:03 +04", "2017-03-10 00:00:00", "2017-03-10 12:34:56", "2017-03-10 01:02:03 +04", "2017-03-10 03:00:00 +03"]', '["2017-03-10", "2017-03-11", "2017-03-09", "12:34:56", "01:02:03 +04", "2017-03-10 00:00:00", "2017-03-10 12:34:56", "2017-03-10 01:02:03 +04", "2017-03-10 03:00:00 +03"]',
'$[*].datetime() ? (@ == "10.03.2017".datetime("dd.mm.yyyy"))'); '$[*].datetime() ? (@ == "10.03.2017".datetime("dd.mm.yyyy"))');
ERROR: cannot convert value from date to timestamptz without timezone usage ERROR: cannot convert value from date to timestamptz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query( select jsonb_path_query(
'["2017-03-10", "2017-03-11", "2017-03-09", "12:34:56", "01:02:03 +04", "2017-03-10 00:00:00", "2017-03-10 12:34:56", "2017-03-10 01:02:03 +04", "2017-03-10 03:00:00 +03"]', '["2017-03-10", "2017-03-11", "2017-03-09", "12:34:56", "01:02:03 +04", "2017-03-10 00:00:00", "2017-03-10 12:34:56", "2017-03-10 01:02:03 +04", "2017-03-10 03:00:00 +03"]',
'$[*].datetime() ? (@ >= "10.03.2017".datetime("dd.mm.yyyy"))'); '$[*].datetime() ? (@ >= "10.03.2017".datetime("dd.mm.yyyy"))');
ERROR: cannot convert value from date to timestamptz without timezone usage ERROR: cannot convert value from date to timestamptz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query( select jsonb_path_query(
'["2017-03-10", "2017-03-11", "2017-03-09", "12:34:56", "01:02:03 +04", "2017-03-10 00:00:00", "2017-03-10 12:34:56", "2017-03-10 01:02:03 +04", "2017-03-10 03:00:00 +03"]', '["2017-03-10", "2017-03-11", "2017-03-09", "12:34:56", "01:02:03 +04", "2017-03-10 00:00:00", "2017-03-10 12:34:56", "2017-03-10 01:02:03 +04", "2017-03-10 03:00:00 +03"]',
'$[*].datetime() ? (@ < "10.03.2017".datetime("dd.mm.yyyy"))'); '$[*].datetime() ? (@ < "10.03.2017".datetime("dd.mm.yyyy"))');
ERROR: cannot convert value from date to timestamptz without timezone usage ERROR: cannot convert value from date to timestamptz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query_tz( select jsonb_path_query_tz(
'["2017-03-10", "2017-03-11", "2017-03-09", "12:34:56", "01:02:03 +04", "2017-03-10 00:00:00", "2017-03-10 12:34:56", "2017-03-10 01:02:03 +04", "2017-03-10 03:00:00 +03"]', '["2017-03-10", "2017-03-11", "2017-03-09", "12:34:56", "01:02:03 +04", "2017-03-10 00:00:00", "2017-03-10 12:34:56", "2017-03-10 01:02:03 +04", "2017-03-10 03:00:00 +03"]',
'$[*].datetime() ? (@ == "10.03.2017".datetime("dd.mm.yyyy"))'); '$[*].datetime() ? (@ == "10.03.2017".datetime("dd.mm.yyyy"))');
...@@ -1996,17 +1996,17 @@ select jsonb_path_query( ...@@ -1996,17 +1996,17 @@ select jsonb_path_query(
'["12:34:00", "12:35:00", "12:36:00", "12:35:00 +00", "12:35:00 +01", "13:35:00 +01", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +01"]', '["12:34:00", "12:35:00", "12:36:00", "12:35:00 +00", "12:35:00 +01", "13:35:00 +01", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +01"]',
'$[*].datetime() ? (@ == "12:35".datetime("HH24:MI"))'); '$[*].datetime() ? (@ == "12:35".datetime("HH24:MI"))');
ERROR: cannot convert value from time to timetz without timezone usage ERROR: cannot convert value from time to timetz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query( select jsonb_path_query(
'["12:34:00", "12:35:00", "12:36:00", "12:35:00 +00", "12:35:00 +01", "13:35:00 +01", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +01"]', '["12:34:00", "12:35:00", "12:36:00", "12:35:00 +00", "12:35:00 +01", "13:35:00 +01", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +01"]',
'$[*].datetime() ? (@ >= "12:35".datetime("HH24:MI"))'); '$[*].datetime() ? (@ >= "12:35".datetime("HH24:MI"))');
ERROR: cannot convert value from time to timetz without timezone usage ERROR: cannot convert value from time to timetz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query( select jsonb_path_query(
'["12:34:00", "12:35:00", "12:36:00", "12:35:00 +00", "12:35:00 +01", "13:35:00 +01", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +01"]', '["12:34:00", "12:35:00", "12:36:00", "12:35:00 +00", "12:35:00 +01", "13:35:00 +01", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +01"]',
'$[*].datetime() ? (@ < "12:35".datetime("HH24:MI"))'); '$[*].datetime() ? (@ < "12:35".datetime("HH24:MI"))');
ERROR: cannot convert value from time to timetz without timezone usage ERROR: cannot convert value from time to timetz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query_tz( select jsonb_path_query_tz(
'["12:34:00", "12:35:00", "12:36:00", "12:35:00 +00", "12:35:00 +01", "13:35:00 +01", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +01"]', '["12:34:00", "12:35:00", "12:36:00", "12:35:00 +00", "12:35:00 +01", "13:35:00 +01", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +01"]',
'$[*].datetime() ? (@ == "12:35".datetime("HH24:MI"))'); '$[*].datetime() ? (@ == "12:35".datetime("HH24:MI"))');
...@@ -2041,17 +2041,17 @@ select jsonb_path_query( ...@@ -2041,17 +2041,17 @@ select jsonb_path_query(
'["12:34:00 +01", "12:35:00 +01", "12:36:00 +01", "12:35:00 +02", "12:35:00 -02", "10:35:00", "11:35:00", "12:35:00", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +1"]', '["12:34:00 +01", "12:35:00 +01", "12:36:00 +01", "12:35:00 +02", "12:35:00 -02", "10:35:00", "11:35:00", "12:35:00", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +1"]',
'$[*].datetime() ? (@ == "12:35 +1".datetime("HH24:MI TZH"))'); '$[*].datetime() ? (@ == "12:35 +1".datetime("HH24:MI TZH"))');
ERROR: cannot convert value from time to timetz without timezone usage ERROR: cannot convert value from time to timetz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query( select jsonb_path_query(
'["12:34:00 +01", "12:35:00 +01", "12:36:00 +01", "12:35:00 +02", "12:35:00 -02", "10:35:00", "11:35:00", "12:35:00", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +1"]', '["12:34:00 +01", "12:35:00 +01", "12:36:00 +01", "12:35:00 +02", "12:35:00 -02", "10:35:00", "11:35:00", "12:35:00", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +1"]',
'$[*].datetime() ? (@ >= "12:35 +1".datetime("HH24:MI TZH"))'); '$[*].datetime() ? (@ >= "12:35 +1".datetime("HH24:MI TZH"))');
ERROR: cannot convert value from time to timetz without timezone usage ERROR: cannot convert value from time to timetz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query( select jsonb_path_query(
'["12:34:00 +01", "12:35:00 +01", "12:36:00 +01", "12:35:00 +02", "12:35:00 -02", "10:35:00", "11:35:00", "12:35:00", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +1"]', '["12:34:00 +01", "12:35:00 +01", "12:36:00 +01", "12:35:00 +02", "12:35:00 -02", "10:35:00", "11:35:00", "12:35:00", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +1"]',
'$[*].datetime() ? (@ < "12:35 +1".datetime("HH24:MI TZH"))'); '$[*].datetime() ? (@ < "12:35 +1".datetime("HH24:MI TZH"))');
ERROR: cannot convert value from time to timetz without timezone usage ERROR: cannot convert value from time to timetz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query_tz( select jsonb_path_query_tz(
'["12:34:00 +01", "12:35:00 +01", "12:36:00 +01", "12:35:00 +02", "12:35:00 -02", "10:35:00", "11:35:00", "12:35:00", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +1"]', '["12:34:00 +01", "12:35:00 +01", "12:36:00 +01", "12:35:00 +02", "12:35:00 -02", "10:35:00", "11:35:00", "12:35:00", "2017-03-10", "2017-03-10 12:35:00", "2017-03-10 12:35:00 +1"]',
'$[*].datetime() ? (@ == "12:35 +1".datetime("HH24:MI TZH"))'); '$[*].datetime() ? (@ == "12:35 +1".datetime("HH24:MI TZH"))');
...@@ -2087,17 +2087,17 @@ select jsonb_path_query( ...@@ -2087,17 +2087,17 @@ select jsonb_path_query(
'["2017-03-10 12:34:00", "2017-03-10 12:35:00", "2017-03-10 12:36:00", "2017-03-10 12:35:00 +01", "2017-03-10 13:35:00 +01", "2017-03-10 12:35:00 -01", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]', '["2017-03-10 12:34:00", "2017-03-10 12:35:00", "2017-03-10 12:36:00", "2017-03-10 12:35:00 +01", "2017-03-10 13:35:00 +01", "2017-03-10 12:35:00 -01", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]',
'$[*].datetime() ? (@ == "10.03.2017 12:35".datetime("dd.mm.yyyy HH24:MI"))'); '$[*].datetime() ? (@ == "10.03.2017 12:35".datetime("dd.mm.yyyy HH24:MI"))');
ERROR: cannot convert value from timestamp to timestamptz without timezone usage ERROR: cannot convert value from timestamp to timestamptz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query( select jsonb_path_query(
'["2017-03-10 12:34:00", "2017-03-10 12:35:00", "2017-03-10 12:36:00", "2017-03-10 12:35:00 +01", "2017-03-10 13:35:00 +01", "2017-03-10 12:35:00 -01", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]', '["2017-03-10 12:34:00", "2017-03-10 12:35:00", "2017-03-10 12:36:00", "2017-03-10 12:35:00 +01", "2017-03-10 13:35:00 +01", "2017-03-10 12:35:00 -01", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]',
'$[*].datetime() ? (@ >= "10.03.2017 12:35".datetime("dd.mm.yyyy HH24:MI"))'); '$[*].datetime() ? (@ >= "10.03.2017 12:35".datetime("dd.mm.yyyy HH24:MI"))');
ERROR: cannot convert value from timestamp to timestamptz without timezone usage ERROR: cannot convert value from timestamp to timestamptz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query( select jsonb_path_query(
'["2017-03-10 12:34:00", "2017-03-10 12:35:00", "2017-03-10 12:36:00", "2017-03-10 12:35:00 +01", "2017-03-10 13:35:00 +01", "2017-03-10 12:35:00 -01", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]', '["2017-03-10 12:34:00", "2017-03-10 12:35:00", "2017-03-10 12:36:00", "2017-03-10 12:35:00 +01", "2017-03-10 13:35:00 +01", "2017-03-10 12:35:00 -01", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]',
'$[*].datetime() ? (@ < "10.03.2017 12:35".datetime("dd.mm.yyyy HH24:MI"))'); '$[*].datetime() ? (@ < "10.03.2017 12:35".datetime("dd.mm.yyyy HH24:MI"))');
ERROR: cannot convert value from timestamp to timestamptz without timezone usage ERROR: cannot convert value from timestamp to timestamptz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query_tz( select jsonb_path_query_tz(
'["2017-03-10 12:34:00", "2017-03-10 12:35:00", "2017-03-10 12:36:00", "2017-03-10 12:35:00 +01", "2017-03-10 13:35:00 +01", "2017-03-10 12:35:00 -01", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]', '["2017-03-10 12:34:00", "2017-03-10 12:35:00", "2017-03-10 12:36:00", "2017-03-10 12:35:00 +01", "2017-03-10 13:35:00 +01", "2017-03-10 12:35:00 -01", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]',
'$[*].datetime() ? (@ == "10.03.2017 12:35".datetime("dd.mm.yyyy HH24:MI"))'); '$[*].datetime() ? (@ == "10.03.2017 12:35".datetime("dd.mm.yyyy HH24:MI"))');
...@@ -2134,17 +2134,17 @@ select jsonb_path_query( ...@@ -2134,17 +2134,17 @@ select jsonb_path_query(
'["2017-03-10 12:34:00 +01", "2017-03-10 12:35:00 +01", "2017-03-10 12:36:00 +01", "2017-03-10 12:35:00 +02", "2017-03-10 12:35:00 -02", "2017-03-10 10:35:00", "2017-03-10 11:35:00", "2017-03-10 12:35:00", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]', '["2017-03-10 12:34:00 +01", "2017-03-10 12:35:00 +01", "2017-03-10 12:36:00 +01", "2017-03-10 12:35:00 +02", "2017-03-10 12:35:00 -02", "2017-03-10 10:35:00", "2017-03-10 11:35:00", "2017-03-10 12:35:00", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]',
'$[*].datetime() ? (@ == "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))'); '$[*].datetime() ? (@ == "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))');
ERROR: cannot convert value from timestamp to timestamptz without timezone usage ERROR: cannot convert value from timestamp to timestamptz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query( select jsonb_path_query(
'["2017-03-10 12:34:00 +01", "2017-03-10 12:35:00 +01", "2017-03-10 12:36:00 +01", "2017-03-10 12:35:00 +02", "2017-03-10 12:35:00 -02", "2017-03-10 10:35:00", "2017-03-10 11:35:00", "2017-03-10 12:35:00", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]', '["2017-03-10 12:34:00 +01", "2017-03-10 12:35:00 +01", "2017-03-10 12:36:00 +01", "2017-03-10 12:35:00 +02", "2017-03-10 12:35:00 -02", "2017-03-10 10:35:00", "2017-03-10 11:35:00", "2017-03-10 12:35:00", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]',
'$[*].datetime() ? (@ >= "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))'); '$[*].datetime() ? (@ >= "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))');
ERROR: cannot convert value from timestamp to timestamptz without timezone usage ERROR: cannot convert value from timestamp to timestamptz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query( select jsonb_path_query(
'["2017-03-10 12:34:00 +01", "2017-03-10 12:35:00 +01", "2017-03-10 12:36:00 +01", "2017-03-10 12:35:00 +02", "2017-03-10 12:35:00 -02", "2017-03-10 10:35:00", "2017-03-10 11:35:00", "2017-03-10 12:35:00", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]', '["2017-03-10 12:34:00 +01", "2017-03-10 12:35:00 +01", "2017-03-10 12:36:00 +01", "2017-03-10 12:35:00 +02", "2017-03-10 12:35:00 -02", "2017-03-10 10:35:00", "2017-03-10 11:35:00", "2017-03-10 12:35:00", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]',
'$[*].datetime() ? (@ < "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))'); '$[*].datetime() ? (@ < "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))');
ERROR: cannot convert value from timestamp to timestamptz without timezone usage ERROR: cannot convert value from timestamp to timestamptz without timezone usage
HINT: use *_tz() function for timezone support HINT: Use *_tz() function for timezone support.
select jsonb_path_query_tz( select jsonb_path_query_tz(
'["2017-03-10 12:34:00 +01", "2017-03-10 12:35:00 +01", "2017-03-10 12:36:00 +01", "2017-03-10 12:35:00 +02", "2017-03-10 12:35:00 -02", "2017-03-10 10:35:00", "2017-03-10 11:35:00", "2017-03-10 12:35:00", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]', '["2017-03-10 12:34:00 +01", "2017-03-10 12:35:00 +01", "2017-03-10 12:36:00 +01", "2017-03-10 12:35:00 +02", "2017-03-10 12:35:00 -02", "2017-03-10 10:35:00", "2017-03-10 11:35:00", "2017-03-10 12:35:00", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]',
'$[*].datetime() ? (@ == "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))'); '$[*].datetime() ? (@ == "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))');
...@@ -2178,6 +2178,13 @@ select jsonb_path_query_tz( ...@@ -2178,6 +2178,13 @@ select jsonb_path_query_tz(
"2017-03-10" "2017-03-10"
(4 rows) (4 rows)
-- overflow during comparison
select jsonb_path_query('"1000000-01-01"', '$.datetime() > "2020-01-01 12:00:00".datetime()'::jsonpath);
jsonb_path_query
------------------
true
(1 row)
set time zone default; set time zone default;
-- jsonpath operators -- jsonpath operators
SELECT jsonb_path_query('[{"a": 1}, {"a": 2}]', '$[*]'); SELECT jsonb_path_query('[{"a": 1}, {"a": 2}]', '$[*]');
......
...@@ -516,6 +516,9 @@ select jsonb_path_query_tz( ...@@ -516,6 +516,9 @@ select jsonb_path_query_tz(
'["2017-03-10 12:34:00 +01", "2017-03-10 12:35:00 +01", "2017-03-10 12:36:00 +01", "2017-03-10 12:35:00 +02", "2017-03-10 12:35:00 -02", "2017-03-10 10:35:00", "2017-03-10 11:35:00", "2017-03-10 12:35:00", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]', '["2017-03-10 12:34:00 +01", "2017-03-10 12:35:00 +01", "2017-03-10 12:36:00 +01", "2017-03-10 12:35:00 +02", "2017-03-10 12:35:00 -02", "2017-03-10 10:35:00", "2017-03-10 11:35:00", "2017-03-10 12:35:00", "2017-03-10", "2017-03-11", "12:34:56", "12:34:56 +01"]',
'$[*].datetime() ? (@ < "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))'); '$[*].datetime() ? (@ < "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))');
-- overflow during comparison
select jsonb_path_query('"1000000-01-01"', '$.datetime() > "2020-01-01 12:00:00".datetime()'::jsonpath);
set time zone default; set time zone default;
-- jsonpath operators -- jsonpath operators
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment