Changing column type from varchar to datestamp in Redshift

Viewed 613

I am trying to create a view from a table and change one of the column types from varchar to a datestamp.

My original_talbe looks like this:

A       B                       C         D
80.00   2020-03-07 19:36:50     testing   approved
80.00   2020-03-07 19:46:50     testing   approved

All of my columns are varchar, I would like to create a view new_view which column type for B would be datestamp.

I have tried:

CREATE OR REPLACE VIEW schema.new_view
AS SELECT * from schema.original_table
alter view original_table alter column date_from_original_table type timestamp using date_created::timestamp;

But I am getting an error:

Invalid operation: syntax error at or near "view"

How can I achieve the outcome of a view having datestamp format for column B?

Thank you for your suggestions.

1 Answers

You can cast the value when you construct the view:

create view schema.new_view as
    select a, b::timestamp, c, d
    from schema.original_table;
Related