Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell ODBC + PostgreSQL + INSERT query

$
0
0

Hi!

I would like to send INSERT query to Postgre SQL. I've installed psqlODBC_x64 and configured System DSN ODBC Connection.

My powershell v3 function for query like SELECT works well:

function Get-ODBC-Data{
    param([string]$query=$(throw 'query is required.'))
    $conn=New-Object System.Data.Odbc.OdbcConnection
    $connStr = "Driver={PostgreSQL Unicode(x64)};Server=SOMENAME;Port=5432;Database=DBNAME;Uid=SOMEUSER;Pwd=SOMEPASS;"
    $conn.ConnectionString= $connStr
    $conn.open
    $cmd=new-object System.Data.Odbc.OdbcCommand($query,$conn)
    $cmd.CommandTimeout=15
    $ds=New-Object system.Data.DataSet
    $da=New-Object system.Data.odbc.odbcDataAdapter($cmd)
    [void]$da.fill($ds)
    $ds.Tables[0]
    $conn.close()
  }
$query = "select * from clients"
$result = Get-ODBC-Data -query $query

But I can't write code that send INSERT query.
Now I using workarouond with psql.exe from pgadmin. But this is two-ways method for one connection.
I googled several times with different key word without effective result. Does enybody have experience with Powershell + posgreSQL ?

Thanks in advance.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>