Re: Error on query execution

From: Igor Korot <ikorot01(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Error on query execution
Date: 2025-03-06 16:34:02
Message-ID: CA+FnnTwCMDVA4VHSsjv3OpFrrnjpyAhiMZyW0mu0X=fVmsfUpA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

H,

On Tue, Mar 4, 2025 at 8:37 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Igor Korot <ikorot01(at)gmail(dot)com> writes:
> > binaryIntVal = htonl( (uint32_t) type );
> > paramValues[0] = (char *) &binaryIntVal;
> > paramLengths[0] = sizeof( binaryIntVal );
> > paramFormats[0] = 1;
>
> You're apparently trying to pass this parameter as an int4 ...
>
> > res = PQexecParams( m_db, "SELECT * FROM abcatfmt WHERE abf_type =
> > $1", 1, nullptr, paramValues, paramLengths, paramFormats, 1 );
>
> ... 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
);

results in:

$1 = L"ERROR: incorrect binary data format in bind parameter 1\n"

I am now at a complete loss.

How do I fix the code so it will run?

Thank you.

>
> regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2025-03-06 17:00:16 Re: Error on query execution
Previous Message Igor Korot 2025-03-06 15:47:21 Re: Quesion about querying distributed databases