Re: dblink: could not send query: another command is already inprogress - Mailing list pgsql-general

From Laurenz Albe
Subject Re: dblink: could not send query: another command is already inprogress
Date
Msg-id 1522822316.2456.9.camel@cybertec.at
Whole thread Raw
In response to Re: dblink: could not send query: another command is already inprogress  (Thiemo Kellner <thiemo@gelassene-pferde.biz>)
List pgsql-general
Thiemo Kellner wrote:
> > The other thing is that you seem to call "dblink_get_result" on any existing
> > connection before use.  But you can only call the function if there is a
> > result outstanding.
> 
> I call dblink_get_result only if I do not open a dblink connection, i. 
> e. only on second and following function calls. I put more notice output 
> into the code showing that dblink_send_query has been called once before 
> the first call of dblink_get_result. I changed my query to reflect 
> return bigint value of the called function write_message_to_table. Error 
> persists.

That's not going to work.
You can only call dblink_get_result if there is an outstanding result.
You cannot call it on an idle connection, that will cause an error.

You should write your code so that whenever dblink_send_query has been
called, you also call dblink_get_result, regardless if the query has
been cancelled or not, so that you always leave the connection in
the "ready for query" state.
Then you don't have to clean up.

Of course you could also ignore the error you get on dblink_get_result,
but that is ugly.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com


pgsql-general by date:

Previous
From: Thiemo Kellner
Date:
Subject: Re: dblink: could not send query: another command is already inprogress
Next
From: Alban Hertroys
Date:
Subject: Re: Concatenate of values in hierarchical data