Re: prepared statement "cu1" already exists (but it does not)

From: Sebastien Flaesch <sebastien(dot)flaesch(at)4js(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: prepared statement "cu1" already exists (but it does not)
Date: 2024-04-09 14:44:18
Message-ID: AM9P191MB1286CCAAF4328B0F5F72109AB0072@AM9P191MB1286.EURP191.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom,

> > Is it an issue if I use the same name for a prepared statement and the server cursor? I mean:
> From memory, I think those share the same "portal" namespace.

Can you please elaborate?

Is it supported to do:

PQprepare(pgConn, "cu1", "declare cu1 cursor for ... ", ... )
PQexecPrepared(pgConn, "cu1", ... )

?

So far this has always worked.

Seb

________________________________
From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Sent: Monday, April 8, 2024 7:36 PM
To: Sebastien Flaesch <sebastien(dot)flaesch(at)4js(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: prepared statement "cu1" already exists (but it does not)

EXTERNAL: Do not click links or open attachments if you do not recognize the sender.

Sebastien Flaesch <sebastien(dot)flaesch(at)4js(dot)com> writes:
> I understand that the whole TX is aborted with PostgreSQL, and probably the deallocate is useless since stmt was prepared inside the TX?

As you can quickly discover with some manual experimentation,
both PREPARE and DEALLOCATE are nontransactional, in the sense
that if they succeed then the prepared statement will exist
(or not) even if the surrounding transaction block is later
rolled back. This is pretty weird, and undocumented I think,
in terms of their role as SQL statements.
It makes a little more sense if you think about the equivalent
wire-protocol-level operations, which are meant to be used
by low-level client code that may not be aware of whether
there is a transaction block in progress.

> Is it an issue if I use the same name for a prepared statement and the server cursor? I mean:

From memory, I think those share the same "portal" namespace.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Sabino Mullane 2024-04-09 14:50:11 Re: Tracing libpq client: Only with PQtrace()?
Previous Message Rajan Pandey 2024-04-09 14:36:00 Re: Postgres_FDW doc doesn't specify TYPE support in Remote Execution Options