问题
Created an external table with a column of type datetime (TIMESTAMP_NTZ type), the external stage has a csv file with null value in the column. Selecting from the external table is giving "Failed to cast variant value "null" to TIMESTAMP_NTZ"
CREATE OR REPLACE EXTERNAL TABLE ext_table_datetime (
col1 datetime as (value:c1::datetime)
)
with location = 's3://bucket_name'
file_format = file_format_1
auto_refresh = true;
Also I have the file format defined as follows, which works for other column types (varchar etc) having null values for external table and also for datetime type in regular table. So, basically just doesn't work for external table with datetime type.
CREATE OR REPLACE FILE FORMAT file_format_1 type = 'CSV'
field_delimiter = ','
ESCAPE_UNENCLOSED_FIELD = NONE
SKIP_HEADER=1
NULL_IF = 'null';
Any ideas on how to load/sync null value into external table datetime type?
回答1:
Have you tried using the NULLIF
function in your EXTERNAL TABLE definition:
CREATE OR REPLACE EXTERNAL TABLE ext_table_datetime (
col1 datetime as (NULLIF(value:c1,'null')::datetime)
)
with location = 's3://bucket_name'
file_format = file_format_1
auto_refresh = true;
Also, since this is a Preview feature for Snowflake, I would suggest opening a support ticket. The NULL_IF parameter of your format file should probably be handling this for you as you expected.
来源:https://stackoverflow.com/questions/61435010/snowflake-external-table-failed-to-cast-variant-value-null-to-datetime-timestamp