Input Time format change

Moderator: NorbertKrupa

Post Reply
User avatar
nnani
Master
Master
Posts: 302
Joined: Fri Apr 13, 2012 6:28 am
Contact:

Input Time format change

Post by nnani » Thu Jul 11, 2013 2:53 pm

Hello all,

I am trying to convert a integer into time data type

Code: Select all

nnani=> select cast(cast(162545 as varchar) as time);
 ?column?
----------
 16:25:45
(1 row)


This is working fine

But when I try

Code: Select all

nnani=> select cast(cast(62545 as varchar) as time);
ERROR 3679:  Invalid input syntax for time: "62545"
nnani=>
It is obvious that Vertica is expecting one more digit for converting the int to Time, but can we somehow give the input as 062545 so that Vertica will give 06:25:45 as the time

I have got this data from flat file and this is the standard it come in.
How do I convert this input "62545" into time.

Thanks
nnani........
Long way to go

You can check out my blogs at vertica-howto

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Input Time format change

Post by JimKnicely » Thu Jul 11, 2013 3:56 pm

I think you gotta get a leading zero in your string:

Code: Select all

dbadmin=> select cast(to_char(62545, '099999') as time);
 to_char
----------
 06:25:45
(1 row)

dbadmin=> select cast(to_char(162545, '099999') as time);
 to_char
----------
 16:25:45
(1 row)
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

User avatar
nnani
Master
Master
Posts: 302
Joined: Fri Apr 13, 2012 6:28 am
Contact:

Re: Input Time format change

Post by nnani » Fri Jul 12, 2013 12:23 pm

Thanks knicely,

That worked like a charm :D
nnani........
Long way to go

You can check out my blogs at vertica-howto

Post Reply

Return to “Vertica Database Development”