Shell脚本使用dblink从一个postgres数据库连接到另一个数据库

时间:2013-09-11 03:26:19

标签: sql postgresql shell

错误:函数dblink_connect_u(text,text)不存在 第3行:来自dblink_connect_u(cast(varchar'dbname = test_db ...              ^ 提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。

亲爱的,

执行我的shell脚本以使用dblink从一个数据库连接到另一个服务器中的另一个数据库时,我遇到了错误。上图显示了我遇到的错误。顺便说一下,我已经检查了linux服务器上的共享目录,我有这个功能: /usr/share/postgresql/8.4/contrib/dblink.sql

但是,为什么我仍然遇到上述错误?

以下是我的shell脚本代码:

echo "Start insert records..."
psql cr032 <<THE_END
select t1.*
into test_table
from dblink_connect_u(cast(varchar 'dbname=TEST_DB port=5432 host=10.0.0.10 user=test password=123456' as text),
            cast(varchar 'select applicationid, appname, appversion, apppath, appdatetime, description, systemtype from test_table' as text))
       as t1(applicationid varchar(36), appname varchar(100), appversion varchar(20), apppath varchar(200), appdatetime timestamp, description text, systemtype smallint);
THE_END
echo "End insert records!"

请提供帮助,非常感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

我找到了错误的根本原因,这是因为我在安装后没有将dblink.sql加载到我的postgres数据库中。 下面是将dblink.sql加载到postgres的命令,在postgres / bin文件夹下执行命令:

psql -d“database_name”&lt; “dblink_location”/dblink.sql

答案 1 :(得分:0)

当您将cast varchar ...省略为文本时会发生什么? 也在思考下面这个问题。使用dblink_connect_u建立连接,然后使用dblink执行查询。

   Select dblink_connect_u( 'connection1',
     'dbname=TEST_DB port=5432 host=10.0.0.10 
        user=test password=123456')

  select t1.*
   into test_table
   from dblink('connection1',
    'select applicationid, appname, appversion, apppath, 
     appdatetime, description, systemtype from test_table' )
   as t1(applicationid varchar(36), appname varchar(100), 
    appversion varchar(20), apppath varchar(200), 
      appdatetime  timestamp, description text, systemtype smallint);
相关问题