Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Powershell v3 + 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:

functionGet-ODBC-Data{
    param([string]$query=$(throw'query is required.'))
    $conn=New-ObjectSystem.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-objectSystem.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 6937

Trending Articles