0

))Hi all, I have an 'Interval' datatype column in mytable that I would like to change to 'character varying' datatype in mytableview.

I know I can change it using...

to_char(interval, 'yy-mm-dd HH24:MI:SS.MS');

But I would like to leave that column datatype as 'interval' in mytable, and make a view of that table changing the 'interval' column to 'character varying' datatype in mytableview.

was so easy...

CREATE TABLE mytable (length INTERVAL);

INSERT INTO mytable (length) VALUES (INTERVAL '1 minute');

CREATE VIEW myview AS
  SELECT to_char(length, 'yy-mm-dd HH24:MI:SS.MS') AS length
  FROM mytable;

Is that possible? Thanks Advanced.

1
  • 1
    Yes, quite possible. Just use the code you are showing in the query you use to build the view. Have you tried that? Commented Jul 2, 2015 at 15:36

1 Answer 1

1

You can specify your view just like you'd specify any other query without needing to change the underlying table types. Here's a Fiddle with your example.

CREATE TABLE mytable (length INTERVAL);

INSERT INTO mytable (length) VALUES (INTERVAL '1 minute');

CREATE VIEW myview AS
  SELECT to_char(length, 'yy-mm-dd HH24:MI:SS.MS') AS length
  FROM mytable;

SELECT * FROM mytable;
-- 0 years 0 mons 0 days 0 hours 1 mins 0.00 secs

SELECT * FROM myview;
-- 00-00-00 00:01:00.000
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.