[PATCH] Add support for leading/trailing bytea trim()ing

Joel Jacobson <joel@compiler.org>

From: "Joel Jacobson" <joel@compiler.org>
To: pgsql-hackers@lists.postgresql.org
Date: 2020-12-04T16:30:43Z
Lists: pgsql-hackers

Attachments

Dear hackers,

Let's say we want to strip the leading zero bytes from '\x0000beefbabe00'::bytea.

This is currently not supported, since trim() for bytea values only support the BOTH mode:

SELECT trim(LEADING '\x00'::bytea FROM '\x0000beefbabe00'::bytea);
ERROR:  function pg_catalog.ltrim(bytea, bytea) does not exist

The attached patch adds LEADING | TRAILING support for the bytea version of trim():

SELECT trim(LEADING '\x00'::bytea FROM '\x0000beefbabe00'::bytea);
    ltrim
--------------
\xbeefbabe00

SELECT trim(TRAILING '\x00'::bytea FROM '\x0000beefbabe00'::bytea);
     rtrim
----------------
\x0000beefbabe

Best regards,

Joel Jacobson

Commits

  1. Add bytea equivalents of ltrim() and rtrim().

  2. Improve our ability to regurgitate SQL-syntax function calls.