Creating a read only VIEW but with different field datatype

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
alexcroox
Forum Newbie
Posts: 2
Joined: Tue Feb 10, 2009 10:32 am

Creating a read only VIEW but with different field datatype

Post 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!
User avatar
sergio-pro
Forum Commoner
Posts: 88
Joined: Sat Dec 27, 2008 12:26 pm

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

Post 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
 
alexcroox
Forum Newbie
Posts: 2
Joined: Tue Feb 10, 2009 10:32 am

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

Post by alexcroox »

perfect thank you!
Post Reply