PostgreSQL的dblink_error_message无法捕获AWS Redshift连接上的错误

时间:2018-12-05 16:16:10

标签: postgresql amazon-redshift amazon-rds dblink

我从一个AWS RDS(Postgresql)实例运行以下脚本:

do
$$
declare 
err text;
conn_name text;
conn_str text;
qry text;

begin

conn_name = 'the_conn';
conn_str = 'host=mycluster.cuvw5xyzklcant.us-east-1.redshift.amazonaws.com port=5439 dbname=mydb user=me password=mypass connect_timeout=200000';
qry = ' COPY test.non_existent_table
                        FROM ''s3://mybucket/this/is/thepath/month=2018-05-01/thefiletouse.txt''
                        IAM_ROLE ''arn:aws:iam::1234567890:role/redshift-service-role''
                        DELIMITER AS ''\t''
                        GZIP
                        TIMEFORMAT ''auto''
                        TRUNCATECOLUMNS
                        ;
                        ';

perform dblink_connect(conn_name, conn_str);
perform dblink_send_query(conn_name, qry); 
err = (SELECT dblink_error_message(conn_name));

raise info '%', err;

end

$$

由于在test.non_existent_table命令中使用了此COPY,使得此操作有意失败。

但是,呼叫:err = (SELECT dblink_error_message(conn_name));返回OK而不是错误消息:

  

错误:XX000:无法复制到不存在的表test.non_existent_table

此文档的链接:https://www.postgresql.org/docs/9.1/contrib-dblink-error-message.html表示以下内容:

  

dblink_error_message-获取命名连接上的最后一条错误消息

文档是否错误以及功能:dblink_error_message仅应检索某些类型的错误消息?还是不能与Redshift一起正常工作?

0 个答案:

没有答案