1

I have the following interface which is connected to a PostgreSQL database:

public interface ExampleDAO extends JpaRepository<Example, Integer>
{
    @Modifying
    @Query(value="COPY my_table FROM :filename CSV HEADER", nativeQuery=true)
    public int copyMyTable(@Param("filename") String filename);
}

But when I run it I get

org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement

I remove the @Param and hardcode the filename in and it works fine. The filename passed is:

copyMyTable("C:\\path\\to\\my\\file.csv");

I am totally at a loss on this one!

0

1 Answer 1

2

Judging from this thread Postgres doesn't support bind parameters in this kind of statement.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for finding the clarity on this! I ended up reading the file in Java line by line and doing the inserts/updates via JPA save function, the file is less than 100 lines so performance is no issue.

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.