Subject: load fom csv

From: Andy Hartman <[email-masked]>
Date: Mon, 16 Sep 2024 11:35:35 -0400

I'm trying to run this piece of code from Powershell and it just sits there
and never comes back. There are only 131 records in the csv.

$connectionString =
"Host=$pgServer;Database=$pgDatabase;Username=$pgUser;Password=$pgPassword"
$copyCommand = "\COPY $pgTable FROM '$csvPath' DELIMITER ',' CSV HEADER;"

psql -h $pgServer -d $pgDatabase -U $pgUser -c $copyCommand

how can I debug this?

Table layout

---

From: Adrian Klaver <[email-masked]>
Date: Mon, 16 Sep 2024 08:45:46 -0700

On 9/16/24 08:35, Andy Hartman wrote:
> I'm trying to run this piece of code from Powershell and it just sits 
> there and never comes back. There are only 131 records in the csv.
> 
> $connectionString = 

1) Look at the Postgres log.

2) Run the psql command outside PowerShell with hard coded connection 
values and -c command.

> image.png

-- 
Adrian Klaver
[email-masked]

---

From: Ron Johnson <[email-masked]>
Date: Mon, 16 Sep 2024 11:47:16 -0400

> psql -h $pgServer -d $pgDatabase -U $pgUser -c $copyCommand

Maybe I'm missing something obvious, but where in the psql command are you
using $connectionString?

-- 
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> crustacean!

---

From: Muhammad Usman Khan <[email-masked]>
Date: Tue, 17 Sep 2024 10:55:24 +0500

Hi,
Try the following options:

   - Check if psql is working independently:
   psql -h $pgServer -d $pgDatabase -U $pgUser -c "SELECT 1;"
   - Check for permission issues on the CSV file
   - Run the command manually without variables
   psql -h your_host -d your_db -U your_user -c "\COPY your_table FROM
   'C:/path/to/your/file.csv' DELIMITER ',' CSV HEADER;"
   - set a timeout using the PGCONNECT_TIMEOUT environment variable:
   $env:PGCONNECT_TIMEOUT=30