pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedSubstring expression fails on single character input
2+ messages / 2 participants
[nested] [flat]
* Substring expression fails on single character input
@ 2020-05-12 12:28 Per-Åke Ling <perake.ling@gmail.com>
2020-05-12 14:10 ` Re: Substring expression fails on single character input Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Per-Åke Ling @ 2020-05-12 12:28 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org
When using the expression *'(\S.*\S)' *to remove surrounding whitespace
(including \t and \n) it returns NULL on single character surrounded by
whitespace.
The following shows the unexpected result:
SELECT x, '|'||substring(x, '(\S.*\S)')||'|'
FROM (VALUES (' a'), (' ab'), (' a b c '), (E' c\n'), (E' ab\n')) AS z (x);
x │ ?column?
──────────┼──────────
a │ <=== ERROR
ab │ |ab|
a b c │ |a b c|
c ↵│ <=== ERROR
│
ab ↵│ |ab|
Regards,
Per-Åke Ling
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Substring expression fails on single character input
2020-05-12 12:28 Substring expression fails on single character input Per-Åke Ling <perake.ling@gmail.com>
@ 2020-05-12 14:10 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2020-05-12 14:10 UTC (permalink / raw)
To: Per-Åke Ling <perake.ling@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org
=?UTF-8?Q?Per=2D=C3=85ke_Ling?= <perake.ling@gmail.com> writes:
> When using the expression *'(\S.*\S)' *to remove surrounding whitespace
> (including \t and \n) it returns NULL on single character surrounded by
> whitespace.
I see no bug there. The pattern requires two non-white-space characters
surrounding some arbitrary text, and your examples don't have that.
If your goal is to trim leading/trailing whitespace I'd suggest that btrim
is a lot easier route to the goal than coming up with a correct regex.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-05-12 14:10 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 12:28 Substring expression fails on single character input Per-Åke Ling <perake.ling@gmail.com>
2020-05-12 14:10 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox