Ticket create error DBD::Pg::st execute failed: ERROR: invalid input

Get this error on some incoming e-mails:

[230110] [Mon Nov 14 00:36:43 2022] [warning]: DBD::Pg::st execute failed: ERROR:  invalid input syntax for type bytea
CONTEXT:  unnamed portal parameter $2 = '...' at /usr/share/perl5/DBIx/SearchBuilder/Handle.pm line 622. (/usr/share/perl5/DBIx/SearchBuilder/Handle.pm:622)

And in PostgreSQL log have this:

2022-11-14 00:36:43.284 EET [230120] xxx@rt5 ERROR:  invalid input syntax for type bytea
2022-11-14 00:36:43.284 EET [230120] xxx@rt5 CONTEXT:  unnamed portal parameter $2 = '...'
2022-11-14 00:36:43.284 EET [230120] xxx@rt5 STATEMENT:  INSERT INTO Attachments (Creator, Content, Parent, TransactionId, ContentEncoding, ContentType, Headers, MessageId, Created, Subject, Filename) VALUES ($1, $2, $3, ...
2022-11-14 00:36:43.289 EET [230120] xxx@rt5 ERROR:  current transaction is aborted, commands ignored until end of transaction block

Problems is causing Content column. Column number $2 is changing because column order is changing on insert.
In PostgreSQL log have lot of error rows on attachment insert followed by dropping legal queries after error:

2022-11-14 00:36:43.845 EEST [61903] xxx@rt5 STATEMENT:  SELECT  * FROM Tickets WHERE id = $1
2022-11-14 00:36:43.849 EEST [61903] xxx@rt5 ERROR:  current transaction is aborted, commands ignored until end of transaction block
2022-11-14 00:36:43.849 EEST [61903] xxx@rt5 STATEMENT:  SELECT * FROM Tickets WHERE id = $1 FOR UPDATE
2022-11-14 00:36:43.854 EEST [61903] xxx@rt5 ERROR:  current transaction is aborted, commands ignored until end of transaction block
2022-11-14 00:36:43.854 EEST [61903] xxx@rt5 STATEMENT:  UPDATE Tickets SET LastUpdated=$1 WHERE id=$2
2022-11-14 00:36:43.858 EEST [61903] xxx@rt5 ERROR:  current transaction is aborted, commands ignored until end of transaction block
2022-11-14 00:36:43.858 EEST [61903] xxx@rt5 STATEMENT:  UPDATE Tickets SET LastUpdatedBy=$1 WHERE id=$2
2022-11-14 00:36:43.864 EEST [61903] xxx@rt5 ERROR:  current transaction is aborted, commands ignored until end of transaction block
2022-11-14 00:36:43.864 EEST [61903] xxx@rt5 STATEMENT:  SELECT  * FROM Tickets WHERE id = $1

Using latest RT (5.0.3) with latest RTIR (5.0.3)