From: Tom Lane <tgl@sss.pgh.pa.us>
To: Raman <ramang@smartdatainc.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Query TIME ZONE
Date: Wed, 28 Jan 2004 00:58:32 -0500
Message-ID: <8028.1075269512@sss.pgh.pa.us> (raw)
In-Reply-To: <003c01c3e55e$54b12d50$d4c7a8c0@raman>
References: <003c01c3e55e$54b12d50$d4c7a8c0@raman>
"Raman" <ramang@smartdatainc.com> writes:
> [ okay: ]
> "select current_time AT TIME ZONE INTERVAL '+5:30'"
> [ not okay: ]
> "select current_time AT TIME ZONE INTERVAL time_difference from customer_events"
"TIME ZONE INTERVAL" is not a SQL construct. You have misunderstood the
interaction of two different SQL constructs:
timestamp AT TIME ZONE timezonespec
INTERVAL 'interval-literal'
One of the possible forms of "timezonespec" in the AT TIME ZONE operator
is an interval value, so your first example works fine. Your second
example does not work because the INTERVAL 'foo' construct is only for
simple literal constants.
> here : time_difference - is my varchar column in the table customer_events.
Why are you using varchar rather than an interval column? An interval
value would work directly in this construct and would provide some
checking that entered values are sane.
If you are absolutely intent on using varchar as the column datatype,
you can do a run-time cast like this:
select current_time AT TIME ZONE "interval"(time_difference) from customer_events
but don't complain when the query fails because some rows contain
time_difference strings that don't look like legal interval values...
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, ramang@smartdatainc.com
Subject: Re: Query TIME ZONE
In-Reply-To: <8028.1075269512@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox