我尝试使用绝对文件路径作为绑定参数。但这会引发语法错误:
exports.up = async (knex: Knex): Promise<any> => {
const dest2 =
'/Users/ldu020/workspace/github.com/mrdulin/nodejs-pg-knex-samples/src/knex-migration/using-a-remove-csv-file/migrations/geotargets-2019-05-02.csv';
await knex.raw(
`
copy t1_geotargets(criteria_id, criteria_name, canonical_name, parent_id, country_code, target_type, status)
from ?? DELIMITER ',' CSV;
`,
[dest2]
);
};
这是错误消息:
migration file "20190515121901_import-a-remote-csv-file.ts" failed
migration failed with error:
copy t1_geotargets(criteria_id, criteria_name, canonical_name, parent_id, country_code, target_type, status)
from "/Users/ldu020/workspace/github"."com/mrdulin/nodejs-pg-knex-samples/src/knex-migration/using-a-remove-csv-file/migrations/geotargets-2019-05-02"."csv" DELIMITER ',' CSV;
- syntax error at or near ""/Users/ldu020/workspace/github""
我该如何解决?
更新
我认为我找到了问题。原因是.
符号。但是不知道如何处理。
答案 0 :(得分:0)
这是不可能的,因为在标识符绑定期间将解释为表名和列名的分隔符。
您必须手动输入knex.raw(`... from "${dest2}" DELIMITER ...`)