Home > Enterprise >  Sum varchar time to a timestamp in Redshift
Sum varchar time to a timestamp in Redshift

Time:08-17

I am trying to sum a timestamp with a time that I have to cast from varchar to time. This is my attempt:

select 
    my_timestamp   cast(my_str_time as time) as my_end_time
from my_db.my_table;

my_timestamp format (already a timestamp):

2022-07-16 02:51:11
2022-07-16 03:18:06
...

my_str_time format (which is a varchar of 50 in the HH:mm:ss format):

00:03:51 
00:04:13
...

The error I'm getting:

specified types or functions (one per info message) not supported on redshift tables

Is there any way to calculate this or I would have to alter that varchar column to time?

CodePudding user response:

You can try to use a combination of to_timestamp and extract (not too pretty but it should work):

extract(sec from to_timestamp(my_str_time,'hh:mi:ss')),

  • Related