We've found an interesting behavior where `char` and `varchar` fields in a table show as the `string` type in a view. Consider the following table and view:
create or replace table thirty_day_tables.kit_varchar_string (
str1 string,
str2 char(10),
str3 varchar(10)
);
create or replace view thirty_day_tables.kit_varchar_string_vw as
select str1, str2, str3, cast("dummy" as varchar(10)) as str4
from thirty_day_tables.kit_varchar_string;
In this case, it mostly works as I expected except for the manufactured field `str4`. The output for `
describe thirty_day_tables.kit_varchar_string_vw`:
col_name | data_type | comment |
str1 | string | null |
str2 | char(10) | null |
str3 | varchar(10) | null |
str4 | string | null |
Why does str4 show as a string despite the explicit cast to a varchar(10)?
Even stranger, if I add a comment to each column I get a different result:
create or replace view thirty_day_tables.kit_varchar_string_vw (
str1 comment "OK - expected to be a string in the view",
str2 comment "ERROR - expected to be a char(10) in the view",
str3 comment "ERROR - expected to be a varchar(10) in the view",
str4 comment "ERROR - expected to be a varchar(10) in the view"
) as
select str1, str2, str3, cast("dummy" as varchar(10)) as str4
from thirty_day_tables.kit_varchar_string;
The output for `describe thirty_day_tables.kit_varchar_string_vw`:
col_name | data_type | comment |
str1 | string | OK - expected to be a string in the view |
str2 | string | ERROR - expected to be a char(10) in the view |
str3 | string | ERROR - expected to be a varchar(10) in the view |
str4 | string | ERROR - expected to be a varchar(10) in the view |
Why do all the columns show as string???