Thread: interval type additional option
Hi
I have a value '400 days 30 sec':: interval
I don't understand why cast
postgres=# select '400days 30sec'::interval minute to second;
+-------------------+
| interval |
+-------------------+
| 400 days 00:00:30 |
+-------------------+
(1 row)
+-------------------+
| interval |
+-------------------+
| 400 days 00:00:30 |
+-------------------+
(1 row)
produce 400 days
or
postgres=# create table foo(a interval minute to second);
CREATE TABLE
postgres=# insert into foo values('400 days');
INSERT 0 1
postgres=# select * from foo;
+----------+
| a |
+----------+
| 400 days |
+----------+
(1 row)
CREATE TABLE
postgres=# insert into foo values('400 days');
INSERT 0 1
postgres=# select * from foo;
+----------+
| a |
+----------+
| 400 days |
+----------+
(1 row)
What is sense of this feature?
Regards
Pavel
>>>>> "Pavel" == Pavel Stehule <pavel.stehule@gmail.com> writes: Pavel> Hi Pavel> I have a value '400 days 30 sec':: interval Pavel> I don't understand why cast Pavel> postgres=# select '400days 30sec'::interval minute to second; ... Pavel> What is sense of this feature? As far as I know it only exists because of the sql spec, and the implementation has never been complete or working. I think it does affect some input parsing cases, there are some nasty hacks here and there to support it, but given that our intervals don't behave like the spec's ones anyway, there seems to be little motivation to make it work fully. These work, for example: select interval '4' year to month; -- 4 months select interval '4' hour; -- 4 hours select interval '4' hour to second; -- 4 seconds select '4'::interval year to month; -- 4 months etc. -- Andrew (irc:RhodiumToad)
čt 31. 1. 2019 v 15:33 odesílatel Andrew Gierth <andrew@tao11.riddles.org.uk> napsal:
>>>>> "Pavel" == Pavel Stehule <pavel.stehule@gmail.com> writes:
Pavel> Hi
Pavel> I have a value '400 days 30 sec':: interval
Pavel> I don't understand why cast
Pavel> postgres=# select '400days 30sec'::interval minute to second;
...
Pavel> What is sense of this feature?
As far as I know it only exists because of the sql spec, and the
implementation has never been complete or working. I think it does
affect some input parsing cases, there are some nasty hacks here and
there to support it, but given that our intervals don't behave like the
spec's ones anyway, there seems to be little motivation to make it work
fully.
yes - it looks little bit bizarre
These work, for example:
select interval '4' year to month; -- 4 months
select interval '4' hour; -- 4 hours
select interval '4' hour to second; -- 4 seconds
select '4'::interval year to month; -- 4 months
etc.
thank you for info
Pavel
--
Andrew (irc:RhodiumToad)