pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Query TIME ZONE
3+ messages / 3 participants
[nested] [flat]

* Query TIME ZONE
@ 2004-01-28 05:19  Raman <ramang@smartdatainc.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Raman @ 2004-01-28 05:19 UTC (permalink / raw)
  To: pgsql-sql

Hi All,
I have a query regarding Time Zone Interval

QUERY:
"select current_time AT TIME ZONE INTERVAL '+5:30'" 
it is running fine

BUT
When I take the value of interval from DB table like:

"select current_time AT TIME ZONE INTERVAL time_difference from customer_events"

here : time_difference - is my varchar column in the table customer_events. This gives me errors " parse error at or near "time_difference" at character 43 "

I tried to type cast it time_difference::text etc but it in vain.

Pls help me ... its realy urgent.

Thanks in advance

Raman Garg

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Query TIME ZONE
@ 2004-01-28 05:58  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Raman <ramang@smartdatainc.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2004-01-28 05:58 UTC (permalink / raw)
  To: Raman <ramang@smartdatainc.com>; +Cc: pgsql-sql

"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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Query TIME ZONE
@ 2004-01-28 06:09  Raman Garg <ramang@smartdatainc.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Raman Garg @ 2004-01-28 06:09 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql

Thanks Tom it worked  for me...
yes I got it wrong.. thanks for the correction.

thanks a lot..
-- Raman

----- Original Message ----- 
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Raman" <ramang@smartdatainc.com>
Cc: <pgsql-sql@postgresql.org>
Sent: Wednesday, January 28, 2004 11:28 AM
Subject: Re: [SQL] Query TIME ZONE


> "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
>




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2004-01-28 06:09 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-01-28 05:19 Query TIME ZONE Raman <ramang@smartdatainc.com>
2004-01-28 05:58 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-01-28 06:09   ` Raman Garg <ramang@smartdatainc.com>

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