Page 1 of 1

Creating a read only VIEW but with different field datatype

Posted: Tue Feb 10, 2009 10:38 am
by alexcroox
Hi,

I am trying to create a VIEW table in Mysql which is read only.

This is fine with;

Code: Select all

CREATE VIEW v_member AS
SELECT *
FROM member
However the whole reason behind using this VIEW is that I need a mirrored table that has the DATE/DATETIME fields in "member" as CHAR in "v_member" instead.

Is there a way to create a VIEW table where you can alter the column datatype? I.e a field called start_date that is type DATE in "member" table will be mirror'd in table v_member, but the corresponding field in there will be type CHAR instead?

Apologies if that makes no sense! Any help would be much appreciated!

Re: Creating a read only VIEW but with different field datatype

Posted: Tue Feb 10, 2009 11:50 am
by sergio-pro
Hi

A simple cast will do it

Code: Select all

 
   CREATE VIEW v_member AS
   SELECT cast(date_created AS char) AS date_created, field2, field3 ...
   FROM member
 

Re: Creating a read only VIEW but with different field datatype

Posted: Tue Feb 10, 2009 11:54 am
by alexcroox
perfect thank you!