Cast INTEGER to INTERVAL (seconds)

Moderator: NorbertKrupa

Post Reply
dbmsuser7
Intermediate
Intermediate
Posts: 71
Joined: Tue Jan 28, 2014 3:03 am

Cast INTEGER to INTERVAL (seconds)

Post by dbmsuser7 » Fri Apr 25, 2014 8:35 pm

Right now I do this as

Code: Select all

CAST(my_integer::VARCHAR || ' s' AS INTERVAL)
Is there a less klunky way of doing it?

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Cast INTEGER to INTERVAL (seconds)

Post by id10t » Fri Apr 25, 2014 10:14 pm

Hi!

[DELETED]
Last edited by id10t on Wed May 06, 2015 5:30 pm, edited 1 time in total.

dbmsuser7
Intermediate
Intermediate
Posts: 71
Joined: Tue Jan 28, 2014 3:03 am

Re: Cast INTEGER to INTERVAL (seconds)

Post by dbmsuser7 » Sat Apr 26, 2014 12:59 am

Thanks, sKwa! You are teh awesome!

Just for my own notes:

Code: Select all

vertica=> SELECT CAST(172 AS INTERVAL SECOND) - CAST(172::VARCHAR || ' s' AS INTERVAL) AS diff;
 diff 
------
 0
(1 row)
Kind of silly of me...I think I read the documention too zealously; they're very restrictive on what casts are allowed, even though those like the one in your method make obvious sense.

Thanks again!

Post Reply

Return to “Vertica SQL”