在delphi中在远程系统上执行Postgres查询时获取本地系统路径

发布于 2025-01-04 08:34:14 字数 1792 浏览 3 评论 0原文

我正在开发一个 delphi 7 应用程序,使用 postgres 9 作为数据库。 该应用程序以两种方式工作,它可以连接到

  1. 本地系统上的 Postgres 数据库
  2. 远程系统上的 Postgres

在本地和远程 postgres 上,数据库将具有相同数量的表。

我们有一个模块,可以使用 COPY 创建数据库表的备份并将结果写入系统上的文件。 示例

query1:='COPY (Select * from mytable where mycolumn in (2011406)) TO 'C:/Documents and Settings/All Users/Documents/drDir/myfile.bck'WITH BINARY'

     Query_dmp_res.SQL.Clear;
     Query_dmp_res.SQL.Add(query1) ;
     Query_dmp_res.ExecSQL;

路径如果本地系统上不存在,则创建 C:/Documents and Settings/All Users/Documents/drDir

由于上述查询是在本地系统上执行的,并且 C:/Documents and Settings/All Users/Documents/drDir/ 也存在 与当地人合作时,这很有效。

但问题是当我们连接到远程系统时。查询 'COPY (Select * from mytable where mycolumn in (2011406)) TO 'C:/Documents and Settings/All Users/Documents/drDir/myfile.bck' WITH BINARY' 失败 因为路径 /drDir/ 是在本地系统上创建的,而不是在远程系统上创建的。

在此处输入图像描述

但即使路径 'C:/Documents and Settings/All Users/Documents/drDir / 存在于远程系统上,文件 /myfile.bck 在远程系统上创建。

谁能告诉我如何

  1. 给出我的系统的路径,以便在执行查询后在我的系统上创建文件/myfile.bck。 这是如何在查询中指定我的本地系统路径 'COPY (Select * from mytable where mycolumn in (2011406)) TO 'myLocalSystemPath/myfile.bck' WITH BINARY'

  2. 如何在远程系统上创建用于执行查询的文件目录.

我尝试将路径更改为 'C:\Documents and Settings\All Users\Documents\drDir\ 但我收到这个错误 在此处输入图像描述

编辑 我试过了

将(从 mytable 中选择 *,其中 mycolumn 在 (2011406) 中)复制到带有二进制的 STDOUT 但如何获取查询结果呢?

im working on a delphi 7 application with postgres 9 as the database.
the application works in two ways, it can connect to the

  1. Postgres database on local system
  2. Postgres on the remote system

On both local and remote postgres the database will have the same number of tables.

we have module where we create backup of the datbase tables using COPY and write the result to a file on the system.
example

query1:='COPY (Select * from mytable where mycolumn in (2011406)) TO 'C:/Documents and Settings/All Users/Documents/drDir/myfile.bck' WITH BINARY'

     Query_dmp_res.SQL.Clear;
     Query_dmp_res.SQL.Add(query1) ;
     Query_dmp_res.ExecSQL;

The path C:/Documents and Settings/All Users/Documents/drDir is created if not existing on the local system.

As the above query is executed on the local system and the C:/Documents and Settings/All Users/Documents/drDir/ exists also
This works fine when working with a local.

But the problem is when we have connected to the remote system.The query
'COPY (Select * from mytable where mycolumn in (2011406)) TO 'C:/Documents and Settings/All Users/Documents/drDir/myfile.bck' WITH BINARY' Fails as the path /drDir/ is created on the local system and not on the remote system.

enter image description here

But even if the path 'C:/Documents and Settings/All Users/Documents/drDir/ exists on the remote system, the File /myfile.bck is created on the remote system.

can any one tell me how to

  1. Give the path of my system, so the file /myfile.bck is created on my system after the query is executed.
    This is How to specify my local system path in the query
    'COPY (Select * from mytable where mycolumn in (2011406)) TO 'myLocalSystemPath/myfile.bck' WITH BINARY'

  2. How to create the File a directory on the remote system for the query execution.

i tried changing the path as 'C:\Documents and Settings\All Users\Documents\drDir\
but i get this error
enter image description here

EDIT
i tried the

COPY (Select * from mytable where mycolumn in (2011406)) TO STDOUT WITH BINARY
but how to get the result of the query?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹊巢 2025-01-11 08:34:14

1)指定文件名时不可能(摘自文档):

带有文件名的 COPY 指示 PostgreSQL 服务器直接读取或写入文件。该文件必须可供服务器访问,并且必须从服务器的角度指定名称。

不过,下一句话给了你一些想法(这也取决于驱动程序):

当指定STDIN或STDOUT时,数据通过客户端和服务器之间的连接传输。

2) 这是服务器访问权限的问题,请咨询您的管理员...但请记住,当您在服务器上创建文件夹时,运行 Postgres 的用户应该对该文件夹具有写入权限。

1) not possible when a filename is specified (excerpt from the docs):

COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the server.

The next sentence though gives you some ideas (and that depends on the drivers also):

When STDIN or STDOUT is specified, data is transmitted via the connection between the client and the server.

2) that's a matter of access to the server, check with your administrator... but bear in mind that when you create a folder on the server the user that Postgres runs under should have write access to that folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文