Mysql – How do i specify a type for a new column through a select statement

MySQL

I'm trying to create a new view from an existing table which as 2 columns:

CREATE TABLE writers (
  movie_id integer NOT NULL REFERENCES movies,
  person_id integer NOT NULL REFERENCES people,
  PRIMARY KEY (movie_id,person_id)
) ;

I'm trying to make a view which adds a new column and a default character value so I want a the new to have the columns movie_id, person_id, position_name and I need position_name to be of type character so that I can union this view with another view.

Is this possible to do?

Best Answer

Yes it is possible:

create view ... as (
    select movie_id, person_id, cast(null as char(1)) as position_name
    from writers
);

I assumed that null (which is part of any type) is what is causing you the problem. Replace null with whatever if that is not the case