pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedStrange timezone 'math' in 9.6.8
4+ messages / 3 participants
[nested] [flat]
* Strange timezone 'math' in 9.6.8
@ 2018-03-28 09:24 Ervin Weber <webervin@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Ervin Weber @ 2018-03-28 09:24 UTC (permalink / raw)
To: pgsql-admin
Seems that PostgreSQL does do math inside invalid time zone names,
without reporting any errors to client if time zone name has sign and
number inside range.
staging=# show server_version;
server_version
----------------
9.6.8
(1 row)
staging=# select now(), now() at time zone 'fubar+167';
now | timezone
-------------------------------+----------------------------
2018-03-28 09:16:25.897444+00 | 2018-03-21 10:16:25.897444
(1 row)
staging=# select now(), now() at time zone 'fubar+168';
ERROR: time zone "fubar+168" not recognized
According to http://sqlfiddle.postgrespro.ru can be reproduced in
11devel and 10.3 (Ubuntu 10.3-1.pgdg16.04+1)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Strange timezone 'math' in 9.6.8
@ 2018-03-28 11:50 Laurenz Albe <laurenz.albe@cybertec.at>
parent: Ervin Weber <webervin@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Laurenz Albe @ 2018-03-28 11:50 UTC (permalink / raw)
To: Ervin Weber <webervin@gmail.com>; pgsql-admin
Ervin Weber wrote:
> Seems that PostgreSQL does do math inside invalid time zone names,
> without reporting any errors to client if time zone name has sign and
> number inside range.
>
> staging=# show server_version;
> server_version
> ----------------
> 9.6.8
> (1 row)
>
> staging=# select now(), now() at time zone 'fubar+167';
> now | timezone
> -------------------------------+----------------------------
> 2018-03-28 09:16:25.897444+00 | 2018-03-21 10:16:25.897444
> (1 row)
>
> staging=# select now(), now() at time zone 'fubar+168';
> ERROR: time zone "fubar+168" not recognized
The cause of the error is the following code in src/timezone/localtime.c,
in function "getsecs":
/*
* Given a pointer into a time zone string, extract a number of seconds,
* in hh[:mm[:ss]] form, from the string.
* If any error occurs, return NULL.
* Otherwise, return a pointer to the first character not part of the number
* of seconds.
*/
static const char *
getsecs(const char *strp, int32 *secsp)
{
int num;
/*
* 'HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
* "M10.4.6/26", which does not conform to Posix, but which specifies the
* equivalent of "02:00 on the first Sunday on or after 23 Oct".
*/
strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
if (strp == NULL)
return NULL;
So any time zone offset that is one week or more fails.
The seemingly arbitrary limit is explained by the comment; the code
serves several purposes.
One could argue that time zones offsets beyound 12 or 24 hours should
cause an error, but apart from that the behavior is correct, right?
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Strange timezone 'math' in 9.6.8
@ 2018-03-28 14:17 Tom Lane <tgl@sss.pgh.pa.us>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2018-03-28 14:17 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: Ervin Weber <webervin@gmail.com>; pgsql-admin
Laurenz Albe <laurenz.albe@cybertec.at> writes:
> Ervin Weber wrote:
>> staging=# select now(), now() at time zone 'fubar+167';
>> [works]
>> staging=# select now(), now() at time zone 'fubar+168';
>> ERROR: time zone "fubar+168" not recognized
> The cause of the error is the following code in src/timezone/localtime.c,
> in function "getsecs":
Also note that that isn't our code; it's lock stock and barrel from the
IANA tzcode distribution,
https://www.iana.org/time-zones
So we are (probably) not the only software that will behave like this.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Strange timezone 'math' in 9.6.8
@ 2018-03-28 16:59 Ervin Weber <webervin@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 4+ messages in thread
From: Ervin Weber @ 2018-03-28 16:59 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Laurenz Albe <laurenz.albe@cybertec.at>; pgsql-admin
Thank you for explantations.
Best, Ervin.
On 28 March 2018 at 17:17, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Laurenz Albe <laurenz.albe@cybertec.at> writes:
>> Ervin Weber wrote:
>>> staging=# select now(), now() at time zone 'fubar+167';
>>> [works]
>>> staging=# select now(), now() at time zone 'fubar+168';
>>> ERROR: time zone "fubar+168" not recognized
>
>> The cause of the error is the following code in src/timezone/localtime.c,
>> in function "getsecs":
>
> Also note that that isn't our code; it's lock stock and barrel from the
> IANA tzcode distribution,
> https://www.iana.org/time-zones
>
> So we are (probably) not the only software that will behave like this.
>
> regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2018-03-28 16:59 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28 09:24 Strange timezone 'math' in 9.6.8 Ervin Weber <webervin@gmail.com>
2018-03-28 11:50 ` Laurenz Albe <laurenz.albe@cybertec.at>
2018-03-28 14:17 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-28 16:59 ` Ervin Weber <webervin@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox