Dervin Thunk
Dervin Thunk

Reputation: 20140

How do I convert string to time in postgresql?

I have a column of type varchar with a time on it like 120217. I would like to convert this to a time format I can query. Would something like

alter table public.table alter column col_time type date using to_date(col_time, 'HHMMSS');

work?

Upvotes: 0

Views: 1314

Answers (1)

Vao Tsun
Vao Tsun

Reputation: 51649

this should do:

alter table public.table 
alter column col_time 
type time using (col_time::time);

Upvotes: 2

Related Questions