From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Jeff Davis <pgsql(at)j-davis(dot)com> |
Cc: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Singleton range constructors versus functional coercion notation |
Date: | 2011-11-19 17:27:09 |
Message-ID: | 19867.1321723629@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
The singleton range constructors don't work terribly well.
regression=# select int4range(42); -- ok
int4range
-----------
[42,43)
(1 row)
regression=# select int4range(null); -- not so ok
int4range
-----------
(1 row)
regression=# select int4range('42'); -- clearly not ok
ERROR: malformed range literal: "42"
LINE 1: select int4range('42');
^
DETAIL: Missing left parenthesis or bracket.
The second of these might at first glance seem all right; until you
remember that range_constructor1 is not strict and throws an error
on null input. So it's not getting called.
What is actually happening in both cases 2 and 3 is that
func_get_detail() is interpreting the syntax as equivalent to
'literal'::int4range. We do not have a whole lot of room to maneuver
here, because that equivalence is of very long standing; and as
mentioned in the comments in that function, we can't easily alter its
priority relative to other interpretations.
I don't immediately see a solution that's better than dropping the
single-argument range constructors. Even if you don't care that much
about the NULL case, things like this are pretty fatal from a usability
standpoint:
regression=# select daterange('2011-11-18');
ERROR: malformed range literal: "2011-11-18"
LINE 1: select daterange('2011-11-18');
^
DETAIL: Missing left parenthesis or bracket.
I'm not sure that singleton ranges are so useful that we need to come up
with a short-form input method for them. (Yeah, I know that this case
could be fixed with an explicit cast, but if we leave it like this we'll
get a constant stream of bug reports about it.)
For that matter, the zero-argument range constructors seem like
mostly a waste of catalog space too ... what's wrong with writing
'empty'::int4range when you need that?
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Stephen Frost | 2011-11-19 17:31:09 | Re: RFC: list API / memory allocations |
Previous Message | Andres Freund | 2011-11-19 16:47:07 | Re: EXPLAIN (plan off, rewrite off) for benchmarking |