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?
this should do:
alter table public.table
alter column col_time
type time using (col_time::time);
to_date returns date - I suppose it just ignores your HHMMSS mask: postgresql.org/docs/current/static/functions-formatting.htmlERROR: result of USING clause for column "col_time" cannot be cast automatically to type date HINT: You might need to add an explicit cast.to_date(int, text)... anyway - updated answer with explicit cast
alter table public.table alter column col_time type date using (col_time)::time;?..