Re: Modifying Arrays

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: umuttechin(at)gmail(dot)com
Cc: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Modifying Arrays
Date: 2023-02-27 15:41:06
Message-ID: 357540.1677512466@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

PG Doc comments form <noreply(at)postgresql(dot)org> writes:
> According to the official document of PostgreSQL 15, in the section 8.15.4.
> Modifying Arrays there is a statement like:

> The slice syntaxes with omitted lower-bound and/or upper-bound can be used
> too, but only when updating an array value that is not NULL or
> zero-dimensional (otherwise, there is no existing subscript limit to
> substitute).

> This statement is not true for the following statements or I am missing
> something?

Your example doesn't use a slice with omitted bound, so I'm not quite sure
what you are trying to show? Using your test data, a slice with omitted
bound does fail with Pam's null schedule:

=> UPDATE sal_emp SET schedule[:2] = '{"w", "x", "y", "z"}' WHERE name = 'Pam';
ERROR: array slice subscript must provide both boundaries
DETAIL: When assigning to a slice of an empty array value, slice boundaries must be fully specified.

but it works for the other entries:

=> UPDATE sal_emp SET schedule[:2] = '{"w", "x", "y", "z"}' WHERE name != 'Pam';
UPDATE 3
=> table sal_emp;
name | pay_by_quarter | schedule
--------+---------------------------+---------------------------------
Pam | {20000,25001,25002,25003} |
Bill | {10000,10000,10000,10000} | {{w,x},{y,z}}
Carol | {20000,25000,25000,25000} | {{w,x},{y,z}}
Carolx | {20000,25001,25002,25003} | {{w,x},{y,z},{meetingy,lunchy}}
(4 rows)

regards, tom lane

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Umut TEKİN 2023-02-27 15:52:46 Re: Modifying Arrays
Previous Message PG Doc comments form 2023-02-27 13:53:27 Modifying Arrays