Subject: dblink_error_message return value

From: PG Doc comments form <[email-masked]>
Date: Wed, 08 Aug 2018 09:16:24 +0000

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/10/static/contrib-dblink-error-message.html
Description:

Documentation says:

Return Value
Returns last error message, or an empty string if there has been no error in
this connection.

Which is invalid.

Actually it returns 'OK' string if no error was raised. Secondly
dblink_is_busy must be first called to make dblink_error_message returns an
error message. (Tested on 9.6.9)

---

From: Tom Lane <[email-masked]>
Date: Wed, 08 Aug 2018 11:57:17 -0400

> Actually it returns 'OK' string if no error was raised.

Good catch!  The code's quite clear about it, but the SGML docs need
fixed.

> Secondly

Meh.  I see what you're getting at here, I think, but that seems like a
completely wrong/misleading statement of the issue.  Joe, can you think of
better phraseology?

			regards, tom lane

---

From: "David G. Johnston" <[email-masked]>
Date: Wed, 8 Aug 2018 09:58:43 -0700

> completely wrong/misleading statement of the issue.  Joe, can you think of

I would suggest that while rewording might be useful a more beneficial
improvement would be separating the commands into "Sync/ASync" and link
back into the corresponding libpq documentation sections which dblink
provides direct SQL layer access to (and which the docs seem to have been
written under the assumption the reader was knowledgeable of that API).  It
does abstract away some of the material in the libpq docs but I think it
would be a reasonable halfway measure in lieu of spending time enhancing
the mostly obsolete dblink extension documentation.

David J.

---

From: Joe Conway <[email-masked]>
Date: Tue, 25 Sep 2018 13:50:11 -0400

> Good catch!  The code's quite clear about it, but the SGML docs need

As mentioned on the nearby thread, will fix. I suppose this ought to be
back-patched.

> completely wrong/misleading statement of the issue.  Joe, can you think of

Maybe a note, something like this?
------------
When asynchronous queries are initiated by dblink_send_query(), the
error message associated with the connection might not get updated until
the server's response message is consumed. This typically means that
dblink_is_busy() or dblink_get_result() should be called prior to
dblink_error_message(), so that any error generated by the asynchronous
query() will be visible.
------------

Joe

-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development

---

From: Joe Conway <[email-masked]>
Date: Tue, 25 Sep 2018 15:58:12 -0400

> Maybe a note, something like this?

And now with the corresponding patch attached.

Thoughts/comments?

Joe
-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development
diff --git a/doc/src/sgml/dblink.sgml b/doc/src/sgml/dblink.sgml
index 87e14ea..97dc3b8 100644
*** a/doc/src/sgml/dblink.sgml
--- b/doc/src/sgml/dblink.sgml
*************** dblink_error_message(text connname) retu
*** 1165,1175 ****
     <title>Return Value</title>
  
     <para>
!     Returns last error message, or an empty string if there has been
      no error in this connection.
     </para>
    </refsect1>
  
    <refsect1>
     <title>Examples</title>
  
--- 1165,1189 ----
     <title>Return Value</title>
  
     <para>
!     Returns last error message, or <literal>OK</literal> if there has been
      no error in this connection.
     </para>
    </refsect1>
  
+   <refsect1>
+    <title>Notes</title>
+ 
+    <para>
+     When asynchronous queries are initiated by
+     <function>dblink_send_query</function>, the error message associated with
+     the connection might not get updated until the server's response message
+     is consumed. This typically means that <function>dblink_is_busy</function>
+     or <function>dblink_get_result</function> should be called prior to
+     <function>dblink_error_message</function>, so that any error generated by
+     the asynchronous query will be visible.
+    </para>
+   </refsect1>
+ 
    <refsect1>
     <title>Examples</title>

---

From: Joe Conway <[email-masked]>
Date: Tue, 2 Oct 2018 08:45:37 -0400

> And now with the corresponding patch attached.

Going once, going twice, ...
(if no complaints will commit soon)

Joe

     <para>
  
    <refsect1>
     <title>Examples</title>
  
--- 1165,1189 ----
  
     <para>
  
+   <refsect1>
+    <title>Notes</title>
+ 
+    <para>

---

From: Joe Conway <[email-masked]>
Date: Sun, 17 Feb 2019 13:19:56 -0500

> (if no complaints will commit soon)

Well, maybe not so soon,  but now done.

Joe