pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Modifying Arrays
3+ messages / 3 participants
[nested] [flat]

* Modifying Arrays
@ 2023-02-27 13:53 PG Doc comments form <noreply@postgresql.org>
  2023-02-27 15:41 ` Re: Modifying Arrays Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Doc comments form @ 2023-02-27 13:53 UTC (permalink / raw)
  To: pgsql-docs@lists.postgresql.org; +Cc: umuttechin@gmail.com

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/15/arrays.html
Description:

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?

CREATE TABLE sal_emp (
    name            text,
    pay_by_quarter  integer[],
    schedule        text[][]
);

INSERT INTO sal_emp
    VALUES ('Bill',
    '{10000, 10000, 10000, 10000}',
    '{{"meeting", "lunch"}, {"training", "presentation"}}');

INSERT INTO sal_emp
    VALUES ('Carol',
    '{20000, 25000, 25000, 25000}',
    '{{"breakfast", "consulting"}, {"meeting", "lunch"}}');

INSERT INTO sal_emp
    VALUES ('Carolx',
    '{20000, 25001, 25002, 25003}',
    '{{"breakfastx", "consultingx"}, {"meetingx", "lunchx"}, {"meetingy",
"lunchy"}}');

INSERT INTO sal_emp
    VALUES ('Sam',
    '{20000, 25001, 25002, 25003}',
    '{}');

INSERT INTO sal_emp
    VALUES ('Pam',
    '{20000, 25001, 25002, 25003}');

SELECT * FROM sal_emp;

UPDATE sal_emp SET schedule[1:2] = '{"asd", "asa"}'
    WHERE name = 'Sam';

UPDATE sal_emp SET schedule[1:2] = '{"x", "y"}'
    WHERE name = 'Pam';

SELECT * FROM sal_emp;

In order to test it: https://dbfiddle.uk/pHKY32u0

Thanks!


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Modifying Arrays
  2023-02-27 13:53 Modifying Arrays PG Doc comments form <noreply@postgresql.org>
@ 2023-02-27 15:41 ` Tom Lane <tgl@sss.pgh.pa.us>
  2023-02-27 15:52   ` Re: Modifying Arrays Umut TEKİN <umuttechin@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2023-02-27 15:41 UTC (permalink / raw)
  To: umuttechin@gmail.com; +Cc: pgsql-docs@lists.postgresql.org

PG Doc comments form <noreply@postgresql.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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Modifying Arrays
  2023-02-27 13:53 Modifying Arrays PG Doc comments form <noreply@postgresql.org>
  2023-02-27 15:41 ` Re: Modifying Arrays Tom Lane <tgl@sss.pgh.pa.us>
@ 2023-02-27 15:52   ` Umut TEKİN <umuttechin@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Umut TEKİN @ 2023-02-27 15:52 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-docs@lists.postgresql.org

Hi Tom,

Thanks for the e - mail. I did interpret it exactly in a different manner,
it was my mistake. I am sorry.

Thanks!

On Mon, Feb 27, 2023 at 4:41 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

> PG Doc comments form <noreply@postgresql.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
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2023-02-27 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-02-27 13:53 Modifying Arrays PG Doc comments form <noreply@postgresql.org>
2023-02-27 15:41 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-02-27 15:52   ` Umut TEKİN <umuttechin@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox