0

I just have a short question. I have a PowerShell script that insert rows into a Postgres table using \copy command. No issue at load, everything goes well.

After the load done, I would like to query the table to count the number of rows inserted and being able to test the value retrieved in my Powershell.

So my problem is to retrieve the result of the Postgres table row count into a PowerShell variable.

I found the below code but even if it does not generates errors it does not return the number of rows in my table.

thanks a lot for your support

$DBCmd             = $DBConn.CreateCommand()
$DBCmd.CommandText = "SELECT COUNT(*) FROM $Load_table_path WHERE audit_trail = '$MyAudit_trail'"     
$rdr               = $DBCmd.ExecuteReader()
$dt                = [System.Data.DataTable]::new()
$dt.Load($rdr)
$dt.Column1
$testtt            = $dt.Column1                
0

1 Answer 1

0

Ok, I finally do like this and get the rowcount for the concerned table.

$query = "SELECT COUNT(*) FROM $table_path WHERE audit_trail = '$MyAudit_trail'"

$rowcount_val = psql -t -h $MyServer -U $MyUid -d $MyDB  -p $MyPort -c $query
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.