Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COPY INTO query on Snowflake returns TABLE does not exist error

I am trying to load data from azure blob storage.

The data has already been staged.

But, the issue is when I try to run

copy into random_table_name
from @stage_name_i_created
file_format = (type='csv')
pattern ='*.csv' 

Below is the error I encounter:

raise error_class(
snowflake.connector.errors.ProgrammingError: 001757 (42601): SQL compilation error:
Table 'random_table_name' does not exist

Basically, it says table does not exist, which it does not, but the syntax on website is the same as mine.

COPY INTO query on Snowflake returns TABLE does not exist error

like image 692
rbachkaniwala Avatar asked May 28 '26 22:05

rbachkaniwala


2 Answers

In my case the table name is case-sensitive. Snowflake seems to convert everything to upper case. I changed the database/schema/table names to all upper-case and it started working.

like image 168
Dumi Avatar answered May 31 '26 17:05

Dumi


First run the below query to fetch the column headers

select $1  FROM @stage_name_i_created/filename.csv limit 1

Assuming below are the header lines from your csv file

   id;first_name;last_name;email;age;location

Create a file_format csv

create or replace file format semicolon
  type = 'CSV'
  field_delimiter = ';'
  skip_header=1;

Then you should define the datatype and field name as below

create or replace table <yourtable> as 
select $1::varchar  as id
,$2::varchar as first_name
,$3::varchar as last_name
,$4::varchar as email
,$5::int as age
,$6::varchar as location
FROM @stage_name_i_created/yourfile.csv  
(file_format => semicolon ); 
like image 28
Leo Avatar answered May 31 '26 17:05

Leo