Reputation: 85
I have a table with a column defined as time CHAR(6)
with values like '18:00'
which I need to convert from char
to time
.
I searched here, but didn't succeed.
Upvotes: 3
Views: 3939
Reputation: 127486
As said, you could use :: to cast, but you could also use the standard CAST() function:
SELECT CAST(my_column AS time) AS my_column_time
FROM my_table;
This also works in other databases, not just PostgreSQL.
Upvotes: 1
Reputation:
If the value really is a valid time, you can just cast it:
select '18:00'::time
Upvotes: 2
Reputation: 312219
You can use the ::
syntax to cast the value:
SELECT my_column::time
FROM my_table
Upvotes: 4