postgresql - Spring JPA @Param of filename for postgres COPY
问题描述
我有以下连接到 PostgreSQL 数据库的接口:
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);
}
但是当我运行它时,我得到
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
我删除@Param
并硬编码文件名,它工作正常。传递的文件名是:
copyMyTable("C:\\path\\to\\my\\file.csv");
我对这个完全不知所措!
解决方案
从这个线程来看, Postgres 不支持这种语句中的绑定参数。
推荐阅读
- sql - 从 JSON 数组中选择唯一值 - PostgreSQL JSON 列
- c - 无法从文件 C 中反向读取输出
- qt - QString 的奇怪行为
- java - 如何在spring boot中加密用户/密码和ftp连接?
- python-3.x - 通过 Anaconda 安装 numpy
- python - 在 pip 中为特定包指定 repo
- amazon-web-services - ssm-agent 试图写入错误的区域
- express - 简单的测试路线没有响应简单的 Postman 请求
- sql - Char(1) vs Number(2) 在 oracle 中性能更好
- c# - 查找 IConfiguration 中是否存在具有空值的 Key