如何使用绝对文件路径作为绑定参数?
How to use a absolute file path as binding parameter?
我尝试使用绝对文件路径作为绑定参数。但它抛出语法错误:
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""
我该如何解决这个问题?
更新
我想我找到了问题所在。原因是 .
符号。但是不知道怎么处理。
这是不可能的,因为在标识符中,绑定句点被解释为 table 和列名的分隔符。
您必须手动输入 knex.raw(`... from "${dest2}" DELIMITER ...`)
我尝试使用绝对文件路径作为绑定参数。但它抛出语法错误:
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""
我该如何解决这个问题?
更新
我想我找到了问题所在。原因是 .
符号。但是不知道怎么处理。
这是不可能的,因为在标识符中,绑定句点被解释为 table 和列名的分隔符。
您必须手动输入 knex.raw(`... from "${dest2}" DELIMITER ...`)