2

I am trying to write this Snowflake query into Java code:

copy into s3://snowflake171
  from USER_TABLE
  storage_integration = s3_int
  file_format = CSV_TEST;

I am writing it like this:

 String q ="COPY INTO s3://snowflake171\n" +
                    "  FROM \"TEST\".\"PUBLIC\".\"USER_TABLE\"WHERE\"ID\\\"=?\"\n" +
                    "  storage_integration = s3_int\n" +
                    "  file_format = CSV_TEST";

But I am getting this error:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [COPY INTO s3://snowflake171
  FROM "TEST"."PUBLIC"."USER_TABLE"WHERE"ID\"=?"
  storage_integration = s3_int
  file_format = CSV_TEST]; nested exception is net.snowflake.client.jdbc.SnowflakeSQLException: SQL compilation error:
syntax error line 1 at position 5 unexpected '<EOF>'.

What am I missing?

4
  • "unexpected 'INOT" - it seems you're not sending INTO but INOT. Please check your code. Commented Oct 20, 2021 at 13:01
  • Sorry I updated it was not that :( Commented Oct 20, 2021 at 13:02
  • WHERE"ID\"=?" - you're missing the parameter here. Also, the query seems to miss the semi-colon at the end: I'd say it should be " file_format = CSV_TEST;"; Commented Oct 20, 2021 at 13:04
  • I have fixed parameter now I HAVE THIS ERROR: SQL access control error: Insufficient privileges to operate on integration 'S3_INT' Commented Oct 20, 2021 at 13:07

1 Answer 1

2

As the latest error message is "SQL access control error: Insufficient privileges to operate on integration 'S3_INT'", can you try to grant USAGE permission on s3_int to your role? Are you sure you set the correct role when connecting?

String url = "jdbc:snowflake://<account_identifier>.snowflakecomputing.com";
Properties prop = new Properties();
prop.put("user", "<user>");
prop.put("privateKey", PrivateKeyReader.get(PRIVATE_KEY_FILE));
prop.put("db", "<database_name>");
prop.put("schema", "<schema_name>");
prop.put("warehouse", "<warehouse_name>");
prop.put("role", "<role_name>");  
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you that was it! There is also possibility to put it in url like this: jdbc:snowflake://account.aws.snowflakecomputing.com/?db=TEST&warehouse=SF_TUTS_WH&schema=PUBLIC&role=ACCOUNTADMIN

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.