且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PowerShell连接到Postgres DB

更新时间:2023-11-18 17:26:46

您可以简单地执行 psql 命令行,然后读取并处理其输出。这在调用 psql -qAt 和/或使用 \copy 时特别有用。

With no client driver at all, you can simply execute the psql command-line then read and process its output. This is particularly useful when invoking it as psql -qAt and/or using \copy.

否则您必须有某种客户端驱动程序。 Powershell没有针对PostgreSQL协议的内置支持代码,因此它无法与PostgreSQL进行通信,没有某种客户端驱动程序。 nPgSQL 将是最明显的选择,因为它在.NET中集成良好,仅由.NET程序集组成。你可能将nPgSQL捆绑为一个Powershell扩展...但是像往常一样,已经有人

Otherwise you must have some kind of client driver. Powershell has no built-in support code for the PostgreSQL protocol, so it therefore cannot communicate with PostgreSQL without some kind of client driver. nPgSQL would be the most obvious choice since it integrates well in .NET and is composed only of .NET assemblies. You could probably bundle nPgSQL up as a Powershell extension... but as usual, someone already did that.

否则你可能想要安装psqlODBC,这是一个简单的 msiexec 然后可以使用通常的ODBC支持

Otherwise you probably want to install psqlODBC, which is a simple msiexec to install then usable using the usual ODBC support.

原因Powershell可以谈到MS SQL而不安装其他驱动程序是MS SQL的驱动程序内置)。

(The only reason Powershell can talk to MS SQL without installing additional drivers is that drivers for MS SQL are built in).