TRIM_ARRAY

From: Vik Fearing <vik(at)postgresfriends(dot)org>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: TRIM_ARRAY
Date: 2021-02-16 17:54:11
Message-ID: fc92ce17-9655-8ff1-c62a-4dc4c8ccd815@postgresfriends.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The SQL standard defines a function called TRIM_ARRAY that surprisingly
has syntax that looks like a function! So I implemented it using a thin
wrapper around our array slice syntax. It is literally just ($1)[1:$2].

An interesting case that I decided to handle by explaining it in the
docs is that this won't give you the first n elements if your lower
bound is not 1. My justification for this is 1) non-standard lower
bounds are so rare in the wild that 2) people using them can just not
use this function. The alternative is to go through the unnest dance
(or write it in C) which defeats inlining.

Patch attached.
--
Vik Fearing

Attachment Content-Type Size
0001-implement-trim_array.patch text/x-patch 4.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Isaac Morland 2021-02-16 18:32:47 Re: TRIM_ARRAY
Previous Message Pavel Stehule 2021-02-16 17:46:13 Re: proposal: schema variables