Substring expression fails on single character input

From: Per-Åke Ling <perake(dot)ling(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Substring expression fails on single character input
Date: 2020-05-12 12:28:43
Message-ID: CACCP6e-Zt8gSoH=PMCLHvGgi-CYYAAi9TE3FrfYcMUjO5BXG9Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2020-05-12 14:10:28 Re: Substring expression fails on single character input
Previous Message Alexander Lakhin 2020-05-12 05:00:01 Re: BUG #16329: Valgrind detects an invalid read when building a gist index with buffering