简体   繁体   中英

Snowflake Database : Loading JSON file from external stage with VALIDATION_MODE in COPY INTO statement

When loading CSV , there is an option to use VALIDATION_MODE with COPY INTO command. This will give us a list of errors in all records in that csv.

COPY INTO "PUBLIC"."TableCSV"
FROM @my_csv_stage
FILES = ('TableCSV.csv')
VALIDATION_MODE = 'RETURN_ERRORS';

When loading JSON , all of these did not work :

COPY INTO "PUBLIC"."TableJSON1"
FROM @my_json_stage
FILES = ('TableJSON1.json')
MATCH_BY_COLUMN_NAME = CASE_SENSITIVE
VALIDATION_MODE = 'RETURN_ERRORS';
COPY INTO "PUBLIC"."TableJSON2"
FROM (
    SELECT $1:"col1" :: VARCHAR
          ,$1:"col2" :: VARCHAR
      FROM @my_json_stage 
  )
FILES = ('TableJSON2.json')
VALIDATION_MODE = 'RETURN_ERRORS';
COPY INTO "PUBLIC"."TableJSON3"
FROM (
    SELECT $1:"col1" :: VARCHAR
          ,$1:"col2" :: VARCHAR
      FROM @my_json_stage 
  )
FILES = ('TableJSON3.json');
SELECT * FROM TABLE(VALIDATE("TableJSON3", job_id => '_last'));

I can see that the first example on this snowflake page has the exact table that I want for JSON, but when I execute

SELECT * FROM TABLE(VALIDATE("TableJSON3", job_id => '_last'));

it gives me this error :

SQL compilation error: JSON/XML/AVRO file format can produce one and only one column of type variant or object or array. Use CSV file format if you want to load more than one column.

This is a known issue in the Snowflake. The engineering team is aware of the issue and they are actively working towards a fix. At this time there is no ETA on the fix timelines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM