range type expression syntax

Started by John Turnerabout 11 years ago4 messagesgeneral
Jump to latest
#1John Turner
jjturner@energi.com

Seems I'm missing a trick trying to get rangetypes working:

No problem building the string:
select concat('''[', now()::date, ',', now()::date, ']''') testrange;
testrange
---------------------------
'[2015-02-26,2015-02-26]'
(1 row)

Bombed-out trying to turn this into a daterange:
postgres=# select concat('''[', now()::date, ',', now()::date,
']''')::daterange testrange;
ERROR: malformed range literal: "'[2015-02-26,2015-02-26]'"
DETAIL: Missing left parenthesis or bracket.

Is there a specific casting I need to apply in order to render a literal
daterange from parameterized range elements?

/john

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2John Turner
jjturner@energi.com
In reply to: John Turner (#1)
Re: range type expression syntax

On Thu, 26 Feb 2015 15:11:28 -0500, John Turner <jjturner@energi.com>
wrote:

Seems I'm missing a trick trying to get rangetypes working:

No problem building the string:
select concat('''[', now()::date, ',', now()::date, ']''') testrange;
testrange
---------------------------
'[2015-02-26,2015-02-26]'
(1 row)

Bombed-out trying to turn this into a daterange:
postgres=# select concat('''[', now()::date, ',', now()::date,
']''')::daterange testrange;
ERROR: malformed range literal: "'[2015-02-26,2015-02-26]'"
DETAIL: Missing left parenthesis or bracket.

Is there a specific casting I need to apply in order to render a literal
daterange from parameterized range elements?

/john

Sorry - too quick to post, I realize there was no need to wrap the
expression in extra quotes:

postgres=# select concat('[', now()::date, ',', now()::date,
']')::daterange testrange;
testrange
-------------------------
[2015-02-26,2015-02-27)
(1 row)

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Marc Mamin
M.Mamin@intershop.de
In reply to: John Turner (#2)
Re: range type expression syntax

postgres=# select concat('[', now()::date, ',', now()::date,
']')::daterange testrange;

There are range specific functions for this:
select daterange(now()::date, now()::date, '[]')

regards,
Marc Mamin

________________________________________
Von: pgsql-general-owner@postgresql.org [pgsql-general-owner@postgresql.org]&quot; im Auftrag von &quot;John Turner [jjturner@energi.com]
Gesendet: Donnerstag, 26. Februar 2015 21:17
An: pgsql-general@postgresql.org
Betreff: Re: [GENERAL] range type expression syntax

On Thu, 26 Feb 2015 15:11:28 -0500, John Turner <jjturner@energi.com>
wrote:

Seems I'm missing a trick trying to get rangetypes working:

No problem building the string:
select concat('''[', now()::date, ',', now()::date, ']''') testrange;
testrange
---------------------------
'[2015-02-26,2015-02-26]'
(1 row)

Bombed-out trying to turn this into a daterange:
postgres=# select concat('''[', now()::date, ',', now()::date,
']''')::daterange testrange;
ERROR: malformed range literal: "'[2015-02-26,2015-02-26]'"
DETAIL: Missing left parenthesis or bracket.

Is there a specific casting I need to apply in order to render a literal
daterange from parameterized range elements?

/john

Sorry - too quick to post, I realize there was no need to wrap the
expression in extra quotes:

postgres=# select concat('[', now()::date, ',', now()::date,
']')::daterange testrange;
testrange
-------------------------
[2015-02-26,2015-02-27)
(1 row)

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4John Turner
jjturner@energi.com
In reply to: Marc Mamin (#3)
Re: range type expression syntax

On Fri, 27 Feb 2015 02:57:15 -0500, Marc Mamin <M.Mamin@intershop.de>
wrote:

postgres=# select concat('[', now()::date, ',', now()::date,
']')::daterange testrange;

There are range specific functions for this:
select daterange(now()::date, now()::date, '[]')

regards,
Marc Mamin

Marc, thanks - indeed it's right there in 8.17.6! As you might suspect,
I'm rushing through things more than I'd care to, so I'm grateful for this
list and the dose of sanity it provides :)

Cheers,
John

_______________________________________

Von: pgsql-general-owner@postgresql.org
[pgsql-general-owner@postgresql.org]&quot; im Auftrag von &quot;John
Turner [jjturner@energi.com]
Gesendet: Donnerstag, 26. Februar 2015 21:17
An: pgsql-general@postgresql.org
Betreff: Re: [GENERAL] range type expression syntax

On Thu, 26 Feb 2015 15:11:28 -0500, John Turner <jjturner@energi.com>
wrote:

Seems I'm missing a trick trying to get rangetypes working:

No problem building the string:
select concat('''[', now()::date, ',', now()::date, ']''') testrange;
testrange
---------------------------
'[2015-02-26,2015-02-26]'
(1 row)

Bombed-out trying to turn this into a daterange:
postgres=# select concat('''[', now()::date, ',', now()::date,
']''')::daterange testrange;
ERROR: malformed range literal: "'[2015-02-26,2015-02-26]'"
DETAIL: Missing left parenthesis or bracket.

Is there a specific casting I need to apply in order to render a literal
daterange from parameterized range elements?

/john

Sorry - too quick to post, I realize there was no need to wrap the
expression in extra quotes:

postgres=# select concat('[', now()::date, ',', now()::date,
']')::daterange testrange;
testrange
-------------------------
[2015-02-26,2015-02-27)
(1 row)

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general