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 1tqEa6-001cGW-6j for pgsql-general@arkaria.postgresql.org; Thu, 06 Mar 2025 17:00:22 +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 1tqEa4-000f4P-RB for pgsql-general@arkaria.postgresql.org; Thu, 06 Mar 2025 17:00:20 +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 1tqEa4-000f4H-Eu for pgsql-general@lists.postgresql.org; Thu, 06 Mar 2025 17:00:20 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tqEa2-001L09-0s for pgsql-general@lists.postgresql.org; Thu, 06 Mar 2025 17:00:19 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 526H0GBE702924; Thu, 6 Mar 2025 12:00:16 -0500 From: Tom Lane To: Igor Korot cc: "pgsql-generallists.postgresql.org" Subject: Re: Error on query execution In-reply-to: References: <225733.1741142220@sss.pgh.pa.us> Comments: In-reply-to Igor Korot message dated "Thu, 06 Mar 2025 15:54:41 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <702922.1741280416.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 06 Mar 2025 12:00:16 -0500 Message-ID: <702923.1741280416@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Igor Korot writes: > On Tue, Mar 4, 2025 at 8:37 PM Tom Lane wrote: >> ... but given that you didn't specify any data type, I think the >> parser will fall back to assuming that $1 is the same type as >> "abf_type", whatever that is. Passing data in binary is not at all >> forgiving about getting the data type right. > Changing the line above to read: > res = PQexecParams( m_db, "SELECT * FROM abcatfmt WHERE abf_type = > $1::smallint", 1, nullptr, paramValues, paramLengths, paramFormats, 1 > ); That just makes it explicit that the query is expecting an int16. You're still passing an int32. You need to either change the parameter setup code to pass an int16, or make the query look more like res = PQexecParams( m_db, "SELECT * FROM abcatfmt WHERE abf_type = $1::integer", 1, nullptr, paramValues, paramLengths, paramFormats, 1); regards, tom lane