0

I'm trying to find a way to set the warehouse dynamically for snowflake via an API so that we can connect to any warehouse at runtime for testing the compute costs across various warehouses.

I've simply passed the warehouse parameter and using a native query to do the job.

@Repository
public interface TestRepository extends JpaRepository<TestEntity, Long>, JpaSpecificationExecutor<TestEntity> {
    @Query(nativeQuery = true, value = "USE WAREHOUSE :warehouse")
    void setWarehouseForSessionTest(@Param("warehouse") String warehouse);
}

However, the parameter is not identified by the query and I'm getting the below exception:

2022-03-25 09:03:08.609 | ERROR | [http-nio-8087-exec-1 - [dispatcherServlet]:175] | Servlet.service() for servlet [dispatcherServlet] in context with path [/api/test] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
net.snowflake.client.jdbc.SnowflakeSQLException: SQL compilation error:
syntax error line 1 at position 14 unexpected '?'.

Can anyone help suggest the right way to do so?

saran3h
  • 10,280
  • 3
  • 31
  • 46
  • I think this has been answered already here: https://stackoverflow.com/questions/56858459/passing-entire-where-clause-to-native-spring-jpa-query – Sergiu Mar 25 '22 at 10:02

0 Answers0