Base de données relationnelle
Find a file
Noah Misch 5d5232bc38 Fix SUBSTRING() for toasted multibyte characters.
Commit 1e7fe06c10 changed
pg_mbstrlen_with_len() to ereport(ERROR) if the input ends in an
incomplete character.  Most callers want that.  text_substring() does
not.  It detoasts the most bytes it could possibly need to get the
requested number of characters.  For example, to extract up to 2 chars
from UTF8, it needs to detoast 8 bytes.  In a string of 3-byte UTF8
chars, 8 bytes spans 2 complete chars and 1 partial char.

Fix this by replacing this pg_mbstrlen_with_len() call with a string
traversal that differs by stopping upon finding as many chars as the
substring could need.  This also makes SUBSTRING() stop raising an
encoding error if the incomplete char is past the end of the substring.
This is consistent with the general philosophy of the above commit,
which was to raise errors on a just-in-time basis.  Before the above
commit, SUBSTRING() never raised an encoding error.

SUBSTRING() has long been detoasting enough for one more char than
needed, because it did not distinguish exclusive and inclusive end
position.  For avoidance of doubt, stop detoasting extra.

Back-patch to v14, like the above commit.  For applications using
SUBSTRING() on non-ASCII column values, consider applying this to your
copy of any of the February 12, 2026 releases.

Reported-by: SATŌ Kentarō <ranvis@gmail.com>
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Bug: #19406
Discussion: https://postgr.es/m/19406-9867fddddd724fca@postgresql.org
Backpatch-through: 14
2026-02-14 12:16:20 -08:00
config Don't put library-supplied -L/-I switches before user-supplied ones. 2025-07-29 15:17:41 -04:00
contrib Further stabilize a postgres_fdw test case. 2026-02-11 11:03:01 -05:00
doc doc: Mention all SELECT privileges required by INSERT ... ON CONFLICT. 2026-02-11 10:52:59 +00:00
src Fix SUBSTRING() for toasted multibyte characters. 2026-02-14 12:16:20 -08:00
.abi-compliance-history Placate ABI checker. 2026-02-07 11:48:14 +13:00
.cirrus.star ci: Simplify ci-os-only handling 2025-08-14 12:02:42 -04:00
.cirrus.tasks.yml Fix typo 2026-01-07 15:48:54 +01:00
.cirrus.yml ci: Per-repo configuration for manually trigger tasks 2025-08-14 11:33:47 -04:00
.dir-locals.el Make Emacs perl-mode indent more like perltidy. 2019-01-13 11:32:31 -08:00
.editorconfig Add .editorconfig 2019-12-18 09:13:13 +01:00
.git-blame-ignore-revs Add previous commit to .git-blame-ignore-revs. 2025-10-21 10:02:19 -05:00
.gitattributes Fix git whitespace warning 2025-08-15 10:32:07 +02:00
.gitignore Update top-level .gitignore. 2022-12-04 15:23:00 -05:00
aclocal.m4 autoconf: Move export_dynamic determination to configure 2022-12-06 18:55:28 -08:00
configure Stamp 17.8. 2026-02-09 16:51:54 -05:00
configure.ac Stamp 17.8. 2026-02-09 16:51:54 -05:00
COPYRIGHT Update copyright for 2026 2026-01-01 13:24:10 -05:00
GNUmakefile.in Allow selecting the git revision to be packaged by "make dist". 2024-05-03 11:08:50 -04:00
HISTORY Canonicalize some URLs 2020-02-10 20:47:50 +01:00
Makefile Adapt REL_17_STABLE to its new status as a stable branch 2024-07-01 08:05:35 +09:00
meson.build Stamp 17.8. 2026-02-09 16:51:54 -05:00
meson_options.txt Allow selecting the git revision to be packaged by "make dist". 2024-05-03 11:08:50 -04:00
README.md Adapt REL_17_STABLE to its new status as a stable branch 2024-07-01 08:05:35 +09:00

PostgreSQL Database Management System

This directory contains the source code distribution of the PostgreSQL database management system.

PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.

Copyright and license information can be found in the file COPYRIGHT.

General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/17/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/17/installation.html.

The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.