Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tCGmV-00FIyl-CI for pgsql-general@arkaria.postgresql.org; Sat, 16 Nov 2024 11:15:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tCGmS-00DyMV-Fb for pgsql-general@arkaria.postgresql.org; Sat, 16 Nov 2024 11:15:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tCGmS-00DyMN-47 for pgsql-general@lists.postgresql.org; Sat, 16 Nov 2024 11:15:56 +0000 Received: from cloud.gatewaynet.com ([185.90.37.94]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tCGmP-002BnM-Db for pgsql-general@lists.postgresql.org; Sat, 16 Nov 2024 11:15:55 +0000 Content-Type: multipart/alternative; boundary="------------8vYJAP7cQCR82J4Vxb0HY1Jx" Message-ID: <40d8beef-ff67-4c6c-828c-2941ca30fdef@cloud.gatewaynet.com> Date: Sat, 16 Nov 2024 13:15:45 +0200 MIME-Version: 1.0 Subject: Re: Getting error 42P02, despite query parameter being sent To: pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Achilleas Mantzios In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------8vYJAP7cQCR82J4Vxb0HY1Jx Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Στις 16/11/24 12:55, ο/η Max Ulidtko έγραψε: > Greetings, group! > > I'm trying to understand a low-level issue. Am evaluating a new client > library for Postgres; it's not particularly popular / mainstream, and > as I've understood so far, sports an independent implementation of PG > binary protocol. > > The issue I'm hitting with it is exemplified by server logs like this: > > 2024-11-16 10:28:19.927 UTC [46] LOG: statement: SET client_encoding = > 'UTF8';SET client_min_messages TO WARNING; > 2024-11-16 10:28:19.928 UTC [46] LOG: execute : CREATE VIEW > public.foobar (alg, hash) AS VALUES ('md5', $1); At least for SQL level prepared statements the statement has to be one of : |SELECT|, |INSERT|, |UPDATE|, |DELETE|, |MERGE|, or |VALUES| |so CREATE is not valid, and I guess the extended protocol prepared statements aint no different in this regard. | > 2024-11-16 10:28:19.928 UTC [46] DETAIL: parameters: $1 = > 'test-param-value' > 2024-11-16 10:28:19.928 UTC [46] ERROR: there is no parameter $1 at > character 57 > > Of course, I /am/ passing a value for parameter $1; and I can trace > that the client lib sends it out on the wire as expected. (Attaching > packet captures.) > > Heck, even the PG server itself says, DETAIL: parameters: $1 = > 'test-param-value' — so it sees the parameter! But then, immediately > unsees it. > > Am I being hit by a PG bug? Is this a known issue? > > I'd retested with master version of that client library, and against 6 > latest major versions of PostgreSQL server (12 throughout to 17). No > difference across versions spotted; the result is consistently error > 42P02. > > Is the client library doing something wrong? How can the server claim > there's no parameter $1 immediately after logging its value it has > received? > > I did minify a 100-line SSCCE that reproduces the issue and can be shared. > > Any advice, or pointers on what to check next besides delving into PG > source, I'd greatly appreciate. Thanks in advance. > > Max > --------------8vYJAP7cQCR82J4Vxb0HY1Jx Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


Στις 16/11/24 12:55, ο/η Max Ulidtko έγραψε:
Greetings, group!

I'm trying to understand a low-level issue. Am evaluating a new client library for Postgres; it's not particularly popular / mainstream, and as I've understood so far, sports an independent implementation of PG binary protocol.

The issue I'm hitting with it is exemplified by server logs like this:

2024-11-16 10:28:19.927 UTC [46] LOG: statement: SET client_encoding = 'UTF8';SET client_min_messages TO WARNING;
2024-11-16 10:28:19.928 UTC [46] LOG: execute <unnamed>: CREATE VIEW public.foobar (alg, hash) AS VALUES ('md5', $1);

At least for SQL level prepared statements the statement has to be one of :

SELECT, INSERT, UPDATE, DELETE, MERGE, or VALUES

so CREATE is not valid, and I guess the extended protocol prepared statements aint no different in this regard.

2024-11-16 10:28:19.928 UTC [46] DETAIL: parameters: $1 = 'test-param-value'
2024-11-16 10:28:19.928 UTC [46] ERROR: there is no parameter $1 at character 57

Of course, I am passing a value for parameter $1; and I can trace that the client lib sends it out on the wire as expected. (Attaching packet captures.)

Heck, even the PG server itself says, DETAIL: parameters: $1 = 'test-param-value' — so it sees the parameter! But then, immediately unsees it.

Am I being hit by a PG bug? Is this a known issue?

I'd retested with master version of that client library, and against 6 latest major versions of PostgreSQL server (12 throughout to 17). No difference across versions spotted; the result is consistently error 42P02.

Is the client library doing something wrong? How can the server claim there's no parameter $1 immediately after logging its value it has received?

I did minify a 100-line SSCCE that reproduces the issue and can be shared.

Any advice, or pointers on what to check next besides delving into PG source, I'd greatly appreciate. Thanks in advance.

Max

--------------8vYJAP7cQCR82J4Vxb0HY1Jx--