Re: operator does not exist: text = bytea

From: Karthik K L V <venkata(dot)karthik4u(at)gmail(dot)com>
To: depesz(at)depesz(dot)com
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: operator does not exist: text = bytea
Date: 2022-07-20 12:59:37
Message-ID: CAGpQzhzUDPrktZp5EidGXnS=C2fjM4CYDh5gP8=0Qn6bC0Nt9A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi depesz,

Thanks for your reply. But, this issue is happening only when the bind
value of the query resolves to null. I am not trying to compare text to
bytes.
And the same query works fine when the bind value gets resolves to some
String. So, looking for an option which can tell Postgres Engine to read *=
null* as *is null*.

On Wed, Jul 20, 2022 at 5:29 PM hubert depesz lubaczewski <depesz(at)depesz(dot)com>
wrote:

> On Wed, Jul 20, 2022 at 03:02:13PM +0530, Karthik K L V wrote:
> > *Caused by: org.postgresql.util.PSQLException: ERROR: operator does not
> > exist: text = bytea Hint: No operator matches the given name and
> argument
> > types. You might need to add explicit type casts. Position: 1037*
> > Could you please let me know how I can resolve this issue without making
> > changes to the query?
>
> I don't think it's possible.
>
> bytea is basically array of bytes.
> text on the other hand is array of characters.
>
> Do the bytes "\xbf\xf3\xb3\x77" equal text "żółw"?
>
> They actually kinda do, if we assume the bytes are text in encoding
> Windows-1252 - in which case the bytes mean "żółw".
>
> But if we'd assume the encoding to be, for example, iso8859-1, then the
> same sequence of bytes means "¿ó³w"
>
> That's why you can't compare bytes to characters.
>
> You have to either convert bytes to text using convert or convert_from
> functions, or change text into bytea using convert_to.
>
> In some cases you can simply cast text to bytea:
>
> $ select 'depesz'::text::bytea;
> bytea
> ────────────────
> \x64657065737a
> (1 row)
>
> which will work using current server encoding, afair.
>
> depesz
>

--
Karthik klv

In response to

Browse pgsql-general by date

  From Date Subject
Next Message H 2022-07-20 13:09:51 Paging through table one row at a ttime
Previous Message Achilleas Mantzios 2022-07-20 12:28:48 Re: pgsql 10.19 : "ERROR: cannot convert infinity to numeric" except there is no infinity