Re: PQexecPrepared() question

From: Igor Korot <ikorot01(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: PQexecPrepared() question
Date: 2025-12-21 05:33:23
Message-ID: CA+FnnTwtd-YJo5zp3obQer3qfbacg5s-4b3+5PvUkL3e+5Eh4Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, Laurenz,

On Fri, Dec 19, 2025 at 10:24 PM Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> wrote:
>
> On Fri, 2025-12-19 at 20:10 -0800, Igor Korot wrote:
> > > > > What is “clientencoding in this case?
> > > >
> > > > - if PGCLIENTENCODING is set in the environment of the client executable, that
> > >
> > > No it is not.
> > >
> > > > - otherwise, if "client_encoding" is set on the server, that
> >
> > I just checked the postgres.conf.
> >
> > This file does not have any client_encoding.
> >
> > > > - otherwise, SQL_ASCII
> >
> > Which means that this is an encoding that will be used.
>
> You can verify that with the SQL statement "SHOW client_encoding"
> in your sample program.

I added the following code in my app:

res = PQexec( m_db, "SHOW client_encoding" );
auto value = PQgetvalue( res, 0, 0 );
PQclear( res );

and the value of the "value" variable is "UTF8".
>
> > But then I don’t understand anything.
> >
> > The code I posted above worked fine on SELECT, but INSERT failed.
> >
> > If the SQL_ASCII is the encoding used both operations should fail. Or both succeeds.
> >
> > Could someone explain what happened?
>
> SQL_ASCII as client encoding means that no conversion will take place.
>
> Still, the database encoding (I suspect UTF8) will govern what can be stored
> in the database. Anything that is not valid UTF-8 will be rejected.
>
> A SELECT will never cause an error - the client will just receive data
> in UTF-8.

The exact error message is:

ERROR: invalid byte sequence for encoding UTF8: 0xdf
CONTEXT: unnamed portal parameter $1

on the INSERT.

Thank you.

>
> Yours,
> Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2025-12-21 05:39:23 Re: PQexecPrepared() question
Previous Message Laurenz Albe 2025-12-20 17:02:13 Re: PQexecPrepared() question