TimestampTz->Text->TimestampTz casting fails with DateStyle 'Postgres' - Mailing list pgsql-bugs

From Aleksander Alekseev
Subject TimestampTz->Text->TimestampTz casting fails with DateStyle 'Postgres'
Date
Msg-id CAJ7c6TOATjJqvhnYsui0=CO5XFMF4dvTGH+skzB--jNhqSQu5g@mail.gmail.com
Whole thread Raw
Responses Re: TimestampTz->Text->TimestampTz casting fails with DateStyle 'Postgres'
List pgsql-bugs
Hi hackers,

We discovered one strange edge case with TimestampTz:

```
=# set datestyle to 'Postgres';
SET
=# SELECT '1000-01-01'::timestamptz::text;
             text
------------------------------
 Wed Jan 01 00:00:00 1000 LMT

=# SELECT '1000-01-01'::timestamptz::text::timestamptz;
ERROR:  invalid input syntax for type timestamp with time zone: "Wed
Jan 01 00:00:00 1000 LMT"
```

When DateStyle is set to 'ISO' everything works fine:

```
=# set datestyle to 'ISO';
SET
=# SELECT '1000-01-01'::timestamptz::text;
             text
------------------------------
 1000-01-01 00:00:00+02:30:17

=# SELECT '1000-01-01'::timestamptz::text::timestamptz;
         timestamptz
------------------------------
 1000-01-01 00:00:00+02:30:17
```

If I understand correctly, text->timestamptz doesn't understand the
'LMT' timezone. Until 1879 it doesn't work, but in 1880 we switch to
'MMT' and then it works:

```
eax=# SELECT '1879-01-01'::timestamptz::text::timestamptz;
ERROR:  invalid input syntax for type timestamp with time zone: "Wed
Jan 01 00:00:00 1879 LMT"
eax=# SELECT '1880-01-01'::timestamptz::text::timestamptz;
         timestamptz
------------------------------
 Wed Dec 31 20:00:17 1879 LMT
(1 row)

eax=# SELECT '1880-01-01'::timestamptz::text;
             text
------------------------------
 Thu Jan 01 00:00:00 1880 MMT
```

It seems to me that in the first case we should either accept "Wed Jan
01 00:00:00 1000 LMT" (since we just generated it) or alternatively
produce something else when casting timestamptz to text.

Thoughts?

-- 
Best regards,
Aleksander Alekseev



pgsql-bugs by date:

Previous
From: Jan Behrens
Date:
Subject: Re: BUG #18693: Column names not set when using SELECT STRICT INTO with RECORD type
Next
From: PG Bug reporting form
Date:
Subject: BUG #18694: DISCARD ALL does not reset execution counters for plpgsql functions