我正在尝试使用“\copy”命令将 txt/csv 文件从 php 导入我的 postgres 数据库。我不能使用 COPY 代替 \copy,因为我需要它作为 psql 客户端执行。我的代码是:
$query = '\\'.'copy data1 FROM "data1.txt" WITH CSV HEADER DELIMITER AS "," QUOTE AS "^"';
$result = pg_query($conn,$query);
if (!$result) {
echo "cannot copy data\n";
} else {
echo "SUCCESS!";
}
当我运行这个 php 文件时,我得到这个错误:
PHP Warning: pg_query(): Query failed: ERROR: syntax error at or near "\"
LINE 1: \copy data1 FROM "data1.txt" WITH ...
^ in script.php on line 30