How can I set the datatype of columns in a mysql view?
The following is incorrect:
CREATE VIEW person_view AS
SELECT 'Test' AS VARCHAR(20) person_firstname,
person.age AS int(2) person_age
FROM person;
table person:
#firstname, lastname, age
john, doe, 8
jane, doe, 5
The example data will trigger the generation of VARCHAR(4) for firstname and int(1) for age. But in fact I want to support VARCHAR(20) and int(2) for those columns in the view.
Try using CAST or CONVERT
CREATE VIEW myview AS SELECT CAST('Test' AS VARCHAR(20)) Column1 FROM mysource;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With