question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error handling VARIANT type

See original GitHub issue

Hi, 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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ftenagliacommented, Jul 22, 2020

@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.

0reactions
IRuscommented, Jul 22, 2020

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:

CREATE TABLE "DATABASE"."SCHEMA"."TABLE_TEMP"(
  DATA_FIELD STRING,
  ANOTHER_FIELD STRING
);

INSERT INTO "DATABASE"."SCHEMA"."TABLE"(DATA_FIELD, ANOTHER_FIELD) SELECT parse_json(t2.DATA_FIELD), t2.ANOTHER_FIELD FROM "DATABASE"."SCHEMA"."TABLE_TEMP" as t2;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle Error Variants - Rust Cookbook
Handles error that occur when trying to open a file that does not exist. It is achieved by using error-chain, a library that...
Read more >
Error Handling - The Rust Programming Language
This particular error type represents the possibility of two types of errors occurring: an error dealing with I/O or an error converting a...
Read more >
Composable Error Handling in OCaml - Vladimir Keleshev
Let's discuss common ways to handle errors in OCaml, their shortcomings, and finally, how polymorphic variants may help.
Read more >
Beginner's guide to Error Handling in Rust - Shesh's blog
In Rust, you return something called a Result . The Result<T, E> type is an enum that has two variants - Ok(T) for...
Read more >
Error Handling · OCaml Tutorials
Here, we add a variant Foo to the type exn , and create a function that will raise this exception. Now, how do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found