我解决了我的问题。我混淆了PostgreSQL
COPY
使用psql的命令
\COPY
指示
实际上,我需要使用
\副本
指令执行复制命令,然后我可以直接从
文件
而不是写信给
stdin
。
[System.Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8
[System.Console]::InputEncoding = [Text.UTF8Encoding]::UTF8
$env:PGPASSWORD = 'pwd';
foreach($file in Get-ChildItem .\Import -Filter *.csv){
$table = $file.BaseName
$Truncate_Sql = "truncate table $table;"
$Result = & psql -h 10.0.xxx.xx -d db1 -U user1 -w -c $Truncate_Sql
Write-Host $Result $table "Ok."
$Result = & psql -h 10.0.xxx.xx -d db1 -U user1 -w -c "\COPY $table FROM $($file.FullName) WITH(FORMAT CSV,HEADER TRUE, ENCODING 'UTF8')"
$Result
}