Skip to content

Bind returns XX000 instead of 26000 for a nonexistent prepared statement #180

Description

@apkipa

Pgpool-II version

4.8devel (master@5c50ba31a49139b552b28ff2f9fd2f6e434f9621), backend_clustering_mode = raw, connection_cache = on, one PostgreSQL backend.

Description

A protocol Bind for a named statement that has not been prepared returns SQLSTATE 26000 with direct PostgreSQL but XX000 through Pgpool. The error text is the same, and both connections remain usable. Pgpool synthesizes the error when Bind() cannot find the statement in its sent-message cache, hard-coding XX000 pool_proto_modules.c; PostgreSQL maps this condition to 26000 (invalid_sql_statement_name) in its error-code appendix.

Reproduce

Install psycopg[binary] and run:

from psycopg.pq import DiagnosticField, ExecStatus, PGconn


def run(label, dsn):
    conn = PGconn.connect(dsn.encode())
    try:
        result = conn.exec_prepared(b"scm_missing_prepared", None, None, 0)
        code = result.error_field(DiagnosticField.SQLSTATE)
        message = result.error_message.decode().strip().removeprefix("ERROR: ").strip()
        followup = conn.exec_(b"SELECT 1")
        value = followup.get_value(0, 0).decode()
        print(
            f"{label}: {ExecStatus(result.status).name}"
            f"[{code.decode() if code else '?'}] {message}; "
            f"followup={ExecStatus(followup.status).name}({value})"
        )
    finally:
        conn.finish()


run("direct", DIRECT_DSN)
run("pgpool", PGPOOL_DSN)

Expected behavior

Both endpoints should return SQLSTATE 26000 and remain usable:

direct: FATAL_ERROR[26000] prepared statement "scm_missing_prepared" does not exist; followup=TUPLES_OK(1)
pgpool: FATAL_ERROR[26000] prepared statement "scm_missing_prepared" does not exist; followup=TUPLES_OK(1)

Actual behavior

The reproducer prints:

direct: FATAL_ERROR[26000] prepared statement "scm_missing_prepared" does not exist; followup=TUPLES_OK(1)
pgpool: FATAL_ERROR[XX000] prepared statement "scm_missing_prepared" does not exist; followup=TUPLES_OK(1)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions