小编ken*_*ken的帖子

使用 Powershell 从 PostgreSQL 检索数据

我一直在努力解决从 Powershell 到 PostgreSQL 的数据库连接问题。我终于能够连接并插入到数据库中。现在我不知道如何从数据库选择中提取数据到变量中。

为了清楚起见,我不包括我的插入内容,但稍后会将其添加到此线程上,因为我知道它很难找到并且可能对某人有帮助。

所以这是我的代码:

# use existing 64 bit ODBC System DSN that we set up manually
$DBconn = New-Object -comobject ADODB.Connection
$DBconn.Open("PostgreSQL35W")

$theQuery = "select * from test1"
$theObject = $DBconn.Execute($theQuery) # $theObject is a System.__ComObject
$numRecords = $theObject.RecordCount
write-host "found $numRecords records"  # getting -1
$theObject.MoveFirst()  # throws no error
# $theValue = $theObject.DataMember # throws no error, but gives no result
$theValue = $theObject.Index[1] # throws "Cannot index into a null array" 
write-host($theValue)
Run Code Online (Sandbox Code Playgroud)

postgresql powershell select

5
推荐指数
2
解决办法
9888
查看次数

标签 统计

postgresql ×1

powershell ×1

select ×1