copy.ps1 431 B

12345678910111213
  1. param (
  2. [string]$db_host,
  3. [int]$db_port,
  4. [string]$db_username,
  5. [string]$db_password,
  6. [string]$dbname,
  7. [string]$table,
  8. [string]$filename,
  9. [string]$columns
  10. )
  11. $env:PGPASSWORD = $db_password
  12. $psqlCommand = "psql -h `"$db_host`" -p $db_port -U `"$db_username`" -d `"$dbname`" -c `"\COPY $table ($columns) FROM '$filename' WITH (FORMAT csv, HEADER true, ENCODING 'UTF8');`""
  13. Invoke-Expression $psqlCommand