On Wed, Jun 3, 2020 at 9:46 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> ...
> ISTM that if the standard intended to allow that, it'd be pretty
> clear. I looked through the 8601 spec just now, and I can't see any
> indication whatever that they intend to allow "-" before P.
To be fair, I do not have an access to 2019 edition that
seems to address negative duration, but what I can see from the wording
at
https://www.loc.gov/standards/datetime/iso-tc154-wg5_n0039_iso_wd_8601-2_2016-02-16.pdf
, it seems to be written without an idea of negative duration at all,
even PT-1D alikes supported by PostgreSQL. Also that PDF mentions comma
as a preferred sign for e.g. PT1,5D that PostgreSQL does not accept. I
understand though that PDF explicitly states it is not a standard.
> It's hard to see why they'd bother with that introducer at all if data
> can appear before it.
I'm not sure I follow. Do you mean to hard require for time/span to
start with P and nothing but that? If so, can we think of it as a
syntactic sugar? I.e. unary minus AND a normal, positive duration of
your liking that we just negate in-place.
>> However, lots of software use leading minus and expect/generate
>> intervals in such forms making those incompatible with current
>> PostgreSQL decoding code.
>
> Which "lots of software" are you speaking of, exactly? interval_in
> has never had such a capability, and I don't recall previous complaints
> about it.
I was not talking about PG-centric software in particular. I had some
JavaScript libraries, Ruby on Rails, Java, Rust, Go in mind. Here is the
related issue for Rust https://github.com/rust-lang/rust/issues/18181
and some Go library
https://pkg.go.dev/github.com/rickb777/date/period?tab=doc#Parse (besides
the links I gave in the patch) to show examples of accepting minus prefix.
I presume no one complained much previously because offset can be (and
often is) stored as float in, e.g., seconds, and then offset * '@1
second'::interval. That looks a bit verbose and I'd prefer to keep
offset as interval and do no extra casting.
Take a look at w3c specs that refer to ISO 8601 as well. I understand,
that is not what PG is after, but here is an excerpt:
,----[ https://www.w3.org/TR/xmlschema-2/#duration ]
| One could also indicate a duration of minus 120 days as: -P120D.
| ...
| P-1347M is not allowed although -P1347M is allowed
`----
Note that the second example explicitly contradicts currently allowed PG
syntax. I presume if the standard was clear, there would be no such
ambiguity.
Not that I'm trying to introduce drastic changes, but to make PostgreSQL
to be somewhat more friendly to what it can accept directly without
dancing around.
--
Mikhail