Re: How to properly use TRIM()?

From: Igor Korot <ikorot01(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How to properly use TRIM()?
Date: 2026-03-07 08:11:18
Message-ID: CA+FnnTzq6DOL6WWoSsK3M_uzQu0HOisbJ4W7J69Gjky1Xo1rGg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, David,

On Sat, Mar 7, 2026 at 1:41 AM David G. Johnston
<david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>
> On Saturday, March 7, 2026, Igor Korot <ikorot01(at)gmail(dot)com> wrote:
>>
>>
>> included, NULLIF( TRIM( c.reloptions ), '' ) AS storage FROM pg_index
>> idx, pg_class c, pg_namespace n, pg_class t, pg_indexes ixs WHERE
>> ixs.indexname = c.relname AND c.oid = idx.indexrelid AND t.oid =
>> idx.indrelid AND n.oid = c.relnamespace AND idx.indisprimary AND
>> n.nspname = 'public' AND t.relname = 'leagues';
>> ERROR: function pg_catalog.btrim(text[]) does not exist
>> LINE 1: ...num) OFFSET idx.indnkeyatts) AS included, NULLIF( TRIM( c.re...
>>
>
>
> You are asking the wrong question. The right question is “how does one turn an empty array into the null value?” Nullif is correct, you just need to specify an empty array (of the correct type) for the second argument.

I don't think pg_class.reloptions is an ARRAY...

draft=# SELECT c.relname AS name, ixs.tablespace, ARRAY(SELECT
a.attname FROM pg_attribute a WHERE a.attrelid = idx.indrelid AND
a.attnum = ANY(idx.indkey) AND a.attnum > 0 ORDER BY
array_position(idx.indkey, a.attnum) OFFSET idx.indnkeyatts) AS
included, c.reloptions AS storage FROM pg_index idx, pg_class c,
pg_namespace n, pg_class t, pg_indexes ixs WHERE ixs.indexname =
c.relname AND c.oid = idx.indexrelid AND t.oid = idx.indrelid AND
n.oid = c.relnamespace AND idx.indisprimary AND n.nspname = 'public'
AND t.relname = 'leagues';
name | tablespace | included | storage
--------------+------------+----------+---------
leagues_pkey | | {} |
(1 row)

Included is one, storage is not.

Thank you.

>
> Given that error message, an array of text is the correct type.
>
> Array[]::text[]
>
> David J.
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Shaheed Haque 2026-03-07 09:24:32 Unexpected deadlock across two separate rows, using Postgres 17 and Django's select_for_update()
Previous Message David G. Johnston 2026-03-07 07:41:43 Re: How to properly use TRIM()?