Re: dblink: could not send query: another command is already in progress

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Thiemo Kellner <thiemo(at)gelassene-pferde(dot)biz>, PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: dblink: could not send query: another command is already in progress
Date: 2018-04-04 06:11:56
Message-ID: 1522822316.2456.9.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Simon Riggs 2018-04-04 07:03:16 Re: [PATCH] Logical decoding of TRUNCATE
Previous Message Peter Eisentraut 2018-04-04 02:31:14 Re: [PATCH] Logical decoding of TRUNCATE