admin管理员组

文章数量:1391000

I'm trying to transform and load a CSV using the COPY INTO command in Snowflake. I keep getting the SQL compilation error in the screen capture below. I've also included an image of the code. How do you address this error for a CSV file?

I'm trying to transform and load data using the COPY INTO command in Snowflake. I get the error in the screen capture.

I'm trying to transform and load a CSV using the COPY INTO command in Snowflake. I keep getting the SQL compilation error in the screen capture below. I've also included an image of the code. How do you address this error for a CSV file?

I'm trying to transform and load data using the COPY INTO command in Snowflake. I get the error in the screen capture.

Share Improve this question asked Mar 16 at 19:07 Robert CrumpRobert Crump 1 4
  • $1 should be the first column, and it will be a string from CSV, because it's a pure string format. So using the JSON access pattern :EMPLOYEE_ID is the same as get($1, 'EMPLOYEE_ID') form, and it is correctly complaining the it does not take string, string as it takes variant, string. I suspect should drop all the :WORD parts you are doing and then you will have success. If your format has a header section, you should be able to use the named columns from that directly. – Simeon Pilgrim Commented Mar 17 at 0:50
  • It's also bad form to dump big pictures where the SQL and error message as TEXT is a) searchable for the next person, and easier to work with for answers. – Simeon Pilgrim Commented Mar 17 at 0:58
  • Thanks, Simon. I'll give that a try. And, thanks for the feedback on dumping big pictures with SQL code. I'm new to forums like this, so I appreciate that input, as well. – Robert Crump Commented Mar 18 at 17:56
  • That worked! Thanks! – Robert Crump Commented Mar 18 at 18:06
Add a comment  | 

1 Answer 1

Reset to default 0

so using VALES as rows from a CSV:

select $1
from values ('col1', 'col2', 'col3');

gives:

$1
col1

but:

select $1:col1
from values ('col1', 'col2', 'col3');

gives:

001044 (42P13): SQL compilation error: error line 1 at position 9

Invalid argument types for function 'GET': (VARCHAR(4), VARCHAR(4))

so you ether should accept all values are text, and name the columns:

select $1 as col1
from values ('col1', 'col2', 'col3');

or if the objects really are JSON and you are accessing subobjects use JSON_EXTRACT_PATH_TEXT for one value per object or PARSE_JSON and then access fields using the :field_name pattern or GET explicitly.

select 
    JSON_EXTRACT_PATH_TEXT($1, 'col1') as col1
from values ('{"col1":"I am a col1"}', 'col2', 'col3');
COL1
I am a col1

本文标签: