Re: some utf8 breaking substring(txt,1,3) but not substring(txt from '^.{4}')
Re: some utf8 breaking substring(txt,1,3) but not substring(txt from '^.{4}')
От:
Hannu Krosing <hannuk@google.com>
Дата:
Body is valid, can be selected in full and the the body can be also
fed to other functions, including version of substring using regexes.
badutf8=# select ctid, id, length(body), length(normalize(body)),
body=normalize(body), octet_length(body),
octet_length(normalize(body)) from bademail;
ctid │ id │ length │ length │ ?column? │ octet_length │ octet_length
───────┼────┼────────┼────────┼──────────┼──────────────┼──────────────
(0,1) │ 1 │ 2314 │ 2314 │ t │ 2323 │ 2323
(1 row)
The most confusing thing is that the byte it complains about in case
of substring(body, 1, 3) or substring(body, 1, 4) does not seem to be
present in the original string at all and definitely not within the
first few characters I ams asking to extract
badutf8=# select ctid, id, substring(body, 1, 2) from bademail;
ctid │ id │ substring
───────┼────┼───────────
(0,1) │ 1 │ Hi
(1 row)
Time: 0.527 ms
badutf8=# select ctid, id, substring(body, 1, 3) from bademail;
ERROR: 22021: invalid byte sequence for encoding "UTF8": 0xc3
LOCATION: report_invalid_encoding_int, mbutils.c:1847
Time: 0.638 ms
badutf8=# select ctid, id, substring(body, 1, 4) from bademail;
ERROR: 22021: invalid byte sequence for encoding "UTF8": 0xc2
LOCATION: report_invalid_encoding_int, mbutils.c:1847
Time: 0.555 ms
badutf8=# select ctid, id, substring(body, 1, 5) from bademail;
ctid │ id │ substring
───────┼────┼───────────
(0,1) │ 1 │ Hi ev
(1 row)
On Fri, May 29, 2026 at 3:29 PM Heikki Linnakangas wrote:
>
> On 29/05/2026 14:44, Hannu Krosing wrote:
> > Hi hackers
> >
> > I was loading our mailing list into a database and noticed that some
> > text results int substring not working.
> >
> > Specifically calling substring with some specific values fails
> >
> > badutf8=# select ctid, id, substring(body, 1, 4) from bademail;
> > ERROR: 22021: invalid byte sequence for encoding "UTF8": 0xc2
> > LOCATION: report_invalid_encoding_int, mbutils.c:1847
> >
> > Asking one byte longer substring works ok
> >
> > badutf8=# select ctid, id, substring(body, 1, 5) from bademail;
> > ctid │ id │ substring
> > ───────┼────┼───────────
> > (0,1) │ 1 │ Hi ev
> > (1 row)
> >
> > as do other ways of getting the same 4 bytes
> >
> > badutf8=# select ctid, id, substring(body from '^.{4}') from bademail;
> > ctid │ id │ substring
> > ───────┼────┼───────────
> > (0,1) │ 1 │ Hi e
> > (1 row)
> >
> > badutf8=# select ctid, id, substring(normalize(body), 1, 4) from bademail;
> > ctid │ id │ substring
> > ───────┼────┼───────────
> > (0,1) │ 1 │ Hi e
> > (1 row)
> >
> > is this expected behaviour and I just have to always noirmalize when
> > loading exotic UTF8 strings ?
>
> Is the body valid UTF-8 or not? If it's not valid, then you shouldn't be
> able to load it into the database in the first place. If it is valid,
> then the substring() should work.
>
> > If you want to replicate this use attached python script to load data
>
> I could not reproduce this. That substring() query after running your
> script works fine for me.
>
> badutf8=# select ctid, id, substring(body, 1, 4) from bademail;
> ctid | id | substring
> -------+----+-----------
> (0,1) | 1 | Hi e
> (1 row)
>
> Which version did you use? What is the database's encoding and what is
> the client encoding? I used 'master', with UTF-8 as server and client
> encoding.
>
> - Heikki
>
Re: some utf8 breaking substring(txt,1,3) but not substring(txt from '^.{4}')
От:
Hannu Krosing <hannuk@google.com>
Дата:
But looks like I can not reproduce it on any other computer (I though
I had verified it on vanill Ubuntu 22.04 as well), so no need to do
any more investigation until I can reproduce it elsewhere
On Fri, May 29, 2026 at 5:16 PM Hannu Krosing wrote:
>
> Body is valid, can be selected in full and the the body can be also
> fed to other functions, including version of substring using regexes.
>
> badutf8=# select ctid, id, length(body), length(normalize(body)),
> body=normalize(body), octet_length(body),
> octet_length(normalize(body)) from bademail;
> ctid │ id │ length │ length │ ?column? │ octet_length │ octet_length
> ───────┼────┼────────┼────────┼──────────┼──────────────┼──────────────
> (0,1) │ 1 │ 2314 │ 2314 │ t │ 2323 │ 2323
> (1 row)
>
> The most confusing thing is that the byte it complains about in case
> of substring(body, 1, 3) or substring(body, 1, 4) does not seem to be
> present in the original string at all and definitely not within the
> first few characters I ams asking to extract
>
>
> badutf8=# select ctid, id, substring(body, 1, 2) from bademail;
> ctid │ id │ substring
> ───────┼────┼───────────
> (0,1) │ 1 │ Hi
> (1 row)
>
> Time: 0.527 ms
> badutf8=# select ctid, id, substring(body, 1, 3) from bademail;
> ERROR: 22021: invalid byte sequence for encoding "UTF8": 0xc3
> LOCATION: report_invalid_encoding_int, mbutils.c:1847
> Time: 0.638 ms
> badutf8=# select ctid, id, substring(body, 1, 4) from bademail;
> ERROR: 22021: invalid byte sequence for encoding "UTF8": 0xc2
> LOCATION: report_invalid_encoding_int, mbutils.c:1847
> Time: 0.555 ms
> badutf8=# select ctid, id, substring(body, 1, 5) from bademail;
> ctid │ id │ substring
> ───────┼────┼───────────
> (0,1) │ 1 │ Hi ev
> (1 row)
>
> On Fri, May 29, 2026 at 3:29 PM Heikki Linnakangas wrote:
> >
> > On 29/05/2026 14:44, Hannu Krosing wrote:
> > > Hi hackers
> > >
> > > I was loading our mailing list into a database and noticed that some
> > > text results int substring not working.
> > >
> > > Specifically calling substring with some specific values fails
> > >
> > > badutf8=# select ctid, id, substring(body, 1, 4) from bademail;
> > > ERROR: 22021: invalid byte sequence for encoding "UTF8": 0xc2
> > > LOCATION: report_invalid_encoding_int, mbutils.c:1847
> > >
> > > Asking one byte longer substring works ok
> > >
> > > badutf8=# select ctid, id, substring(body, 1, 5) from bademail;
> > > ctid │ id │ substring
> > > ───────┼────┼───────────
> > > (0,1) │ 1 │ Hi ev
> > > (1 row)
> > >
> > > as do other ways of getting the same 4 bytes
> > >
> > > badutf8=# select ctid, id, substring(body from '^.{4}') from bademail;
> > > ctid │ id │ substring
> > > ───────┼────┼───────────
> > > (0,1) │ 1 │ Hi e
> > > (1 row)
> > >
> > > badutf8=# select ctid, id, substring(normalize(body), 1, 4) from bademail;
> > > ctid │ id │ substring
> > > ───────┼────┼───────────
> > > (0,1) │ 1 │ Hi e
> > > (1 row)
> > >
> > > is this expected behaviour and I just have to always noirmalize when
> > > loading exotic UTF8 strings ?
> >
> > Is the body valid UTF-8 or not? If it's not valid, then you shouldn't be
> > able to load it into the database in the first place. If it is valid,
> > then the substring() should work.
> >
> > > If you want to replicate this use attached python script to load data
> >
> > I could not reproduce this. That substring() query after running your
> > script works fine for me.
> >
> > badutf8=# select ctid, id, substring(body, 1, 4) from bademail;
> > ctid | id | substring
> > -------+----+-----------
> > (0,1) | 1 | Hi e
> > (1 row)
> >
> > Which version did you use? What is the database's encoding and what is
> > the client encoding? I used 'master', with UTF-8 as server and client
> > encoding.
> >
> > - Heikki
> >
Re: some utf8 breaking substring(txt,1,3) but not substring(txt from '^.{4}')
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Sat, May 30, 2026 at 12:35 AM Hannu Krosing wrote: > > But looks like I can not reproduce it on any other computer (I though > I had verified it on vanill Ubuntu 22.04 as well), so no need to do > any more investigation until I can reproduce it elsewhere This is just a *guess*, but is it possible that you were using a bit older PostgreSQL version and hit the same issue reported at [1]? If so, this issue was already fixed by commit 9f4fd119b2c. Regards, [1] https://postgr.es/m/19406-9867fddddd724fca@postgresql.org -- Fujii Masao
Re: [PATCH v2] Don't stop a `vacuumdb --all` on a connection failure
Hi Christophe,
+1.
Best regards,
-- Thanks for the v2. All three points from my earlier review are
addressed, and the --continue approach looks good to me.
addressed, and the --continue approach looks good to me.
+1.
Best regards,
Re: [PATCH v2] Don't stop a `vacuumdb --all` on a connection failure
> On Jul 29, 2026, at 17:45, Neil Chen wrote: > Thanks for the v2. All three points from my earlier review are > addressed, and the --continue approach looks good to me. Thank you! (And thank you, Daniel.) I've added it to the open CF.
Re: [PATCH v3] Don't stop a `vacuumdb/reindex/ --all` on a connection failure
Another turn on this patch to clear cfbot errors.
Re: [Patch] Don't stop a `vacuumdb --all` on a connection failure
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Mon, Aug 31, 2026 at 10:42 PM Pierre Forstmann wrote: > The new status of this patch is: Ready for Committer I have a few questions about the proposed behavior. vacuumdb already exits with status 0 when VACUUM skips tables with a warning due to, e.g., insufficient privileges, as long as no other errors occur. So, could we treat skipped databases the same way and make this the default, without adding a new --continue option? *If* we do need an option, --continue sounds broader than its actual scope. Using the prefix --skip for the option name is better, following the naming of the existing option --skip-locked? Also, additional connections for --jobs still use fail_ok=false in connect_slot(). So, --continue can still abort the entire run if an additional connection fails, for example, due to a database connection limit. Is this intentional? Regards, -- Fujii Masao