Re: pgsql: Implement jsonpath .datetime() method

2019-10-19 Thread Alexander Korotkov
On Mon, Oct 14, 2019 at 5:36 AM Alexander Korotkov
 wrote:
> On Sun, Oct 13, 2019 at 5:24 AM Tom Lane  wrote:
> > Alexander Korotkov  writes:
> > > This patch also changes the way timestamp to timestamptz cast works.
> > > Previously it did timestamp2tm() then tm2timestamp().  Instead, after
> > > timestamp2tm() it calculates timezone offset and applies it to
> > > original timestamp value.  I hope this is correct.
> >
> > I'd wonder whether this gives the same answers near DST transitions,
> > where it's not real clear which offset applies.
>
> I will try this and share the results.

I've separated refactoring of timestamp to timestamptz cast into a
separate patch.  Patchset is attached.

I've investigates the behavior near DST transitions in Moscow
timezone.  Last two DST transitions it had in 2010-03-28 and
2010-10-31.  It behaves the same with and without patch.  The tests
are below.

# set timezone = 'Europe/Moscow';

# select '2010-03-28 01:59:59'::timestamp::timestamptz;
  timestamptz

 2010-03-28 01:59:59+03
(1 row)

# select '2010-03-28 02:00:00'::timestamp::timestamptz;
  timestamptz

 2010-03-28 03:00:00+04
(1 row)

# select '2010-03-28 02:59:59'::timestamp::timestamptz;
  timestamptz

 2010-03-28 03:59:59+04
(1 row)

# select '2010-03-28 03:00:00'::timestamp::timestamptz;
  timestamptz

 2010-03-28 03:00:00+04
(1 row)

# select '2010-10-31 01:59:59'::timestamp::timestamptz;
  timestamptz

 2010-10-31 01:59:59+04
(1 row)

# select '2010-10-31 02:00:00'::timestamp::timestamptz;
  timestamptz

 2010-10-31 02:00:00+03
(1 row)

BTW, I've noticed how ridiculous cast behaves for values in the range
of [2010-03-28 02:00:00, 2010-03-28 03:00:00).  Now, I think that
timestamptz type, which explicitly stores timezone offset, has some
point.  At least, it would be possible to save the same local time
value during casts.

I'm going to push these two patches if no objections.

--
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company


0001-Refactor-timestamp2timestamptz_opt_error-3.patch
Description: Binary data


0002-Refactor-jsonpath-s-compareDatetime-3.patch
Description: Binary data


pgsql: Fix most -Wundef warnings

2019-10-19 Thread Peter Eisentraut
Fix most -Wundef warnings

In some cases #if was used instead of #ifdef in an inconsistent style.
Cleaning this up also helps when analyzing cases like
38d8dce61fff09daae0edb6bcdd42b0c7f10ebcd where this makes a
difference.

There are no behavior changes here, but the change in pg_bswap.h would
prevent possible accidental misuse by third-party code.

Discussion: 
https://www.postgresql.org/message-id/flat/3b615ca5-c595-3f1d-fdf7-a429e564f614%402ndquadrant.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/5d3587d14b753cb25b0ebcd549d95e1b6ceebce4

Modified Files
--
contrib/hstore/hstore_compat.c  |  2 +-
contrib/pg_standby/pg_standby.c |  2 +-
contrib/pgcrypto/imath.c|  4 ++--
src/backend/libpq/be-fsstubs.c  |  4 ++--
src/backend/replication/logical/reorderbuffer.c |  2 +-
src/backend/storage/file/fd.c   |  2 +-
src/backend/utils/hash/dynahash.c   | 14 +++---
src/backend/utils/mmgr/freepage.c   |  2 +-
src/include/port/pg_bswap.h |  8 
src/port/snprintf.c |  4 ++--
src/port/win32error.c   |  2 +-
11 files changed, 27 insertions(+), 19 deletions(-)