Retrieve data from PostgreSQL using Powershell -


i have been wrestling database connection postgresql powershell. able connect , insert database. can't figure out how extract data db select variable.

i'm not including insert sake of clarity tack onto thread later know super hard find , may helpful someone.

so here's code:

# use existing 64 bit odbc system dsn set manually $dbconn = new-object -comobject adodb.connection $dbconn.open("postgresql35w")  $thequery = "select * test1" $theobject = $dbconn.execute($thequery) # $theobject system.__comobject $numrecords = $theobject.recordcount write-host "found $numrecords records"  # getting -1 $theobject.movefirst()  # throws no error # $thevalue = $theobject.datamember # throws no error, gives no result $thevalue = $theobject.index[1] # throws "cannot index null array"  write-host($thevalue) 

i ended figuring out - here's did

$conn = new-object -comobject adodb.connection  # use existing 64 bit odbc system dsn set manually $conn.open("postgresql35w")  $recordset = $conn.execute("select * jobhistory") while ($recordset.eof -ne $true)  {       foreach ($field in $recordset.fields)     {             '{0,30} = {1,-30}' -f # line sets nice pretty field format, don't need         $field.name, $field.value       }    ''  # line adds line between records $recordset.movenext() }  $conn.close(); exit 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -