Substring expression fails on single character input - Mailing list pgsql-bugs

From Per-Åke Ling
Subject Substring expression fails on single character input
Date
Msg-id CACCP6e-Zt8gSoH=PMCLHvGgi-CYYAAi9TE3FrfYcMUjO5BXG9Q@mail.gmail.com
Whole thread Raw
Responses Re: Substring expression fails on single character input  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-bugs by date:

Previous
From: Alexander Lakhin
Date:
Subject: Re: BUG #16329: Valgrind detects an invalid read when building a gistindex with buffering
Next
From: Tom Lane
Date:
Subject: Re: Substring expression fails on single character input