Error handling VARIANT type
See original GitHub issueHi, I created a table as follows:
create table MyTable (MyField VARIANT);
And, I tried to insert a record using COPY command with internal staging. The ultimate copy command invoked is:
COPY INTO "PUBLIC"."MYTABLE" ("MYFIELD") FROM '@~/INPUTVIEW/5276cb94-9dc8-42fc-a0a6-98d2f265a1dc' FILE_FORMAT = ( FIELD_OPTIONALLY_ENCLOSED_BY = '\\'' ESCAPE = '\\\\') ON_ERROR = 'ABORT_STATEMENT'
If the file content is just as follows it works without any problem: {“name”:“syed”, “role”:“dev”}
However, if I en-quote the entire value in the file as below, it fails: ‘{“name”:“syed”, “role”:“dev”}’
The error is:
net.snowflake.client.jdbc.SnowflakeSQLException: Error parsing JSON ........
In order to overcome the above error, I had to modify the COPY command by adding few more options,
COPY INTO "PUBLIC"."MYTABLE" ("MYFIELD") FROM '@~/INPUTVIEW/5276cb94-9dc8-42fc-a0a6-98d2f265a1dc' FILE_FORMAT = ( EMPTY_FIELD_AS_NULL = false NULL_IF = '_NULL_d017d071-738b-4821-8724-9cb6dfc4b904' FIELD_OPTIONALLY_ENCLOSED_BY = '\\'' ESCAPE = '\\\\') ON_ERROR = 'ABORT_STATEMENT'
My question is why do I have to modify the COPY command? If I change my data type in the table from VARIANT to VARCHAR then the first COPY command (without the EMPTY_FIELD_AS_NULL and NULL_IF options) works for the data value enquoted in the file.
Can someone clarify if this could be bug from the snowflake end?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (1 by maintainers)
Top GitHub Comments
@IRus that’s what I’m trying to do, I guess it still requires less effort than handling a file for COPY. Thanks for the input.
Also approach with temporary table where variant data is STRING, and than copy this data from temp to actual table works much faster, but required additional table and moving data between tables: