Re: [HACKERS] [PATCH] Generic type subscripting

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Justin Pryzby <pryzby(at)telsasoft(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, David Steele <david(at)pgmasters(dot)net>, Nikita Glukhov <n(dot)gluhov(at)postgrespro(dot)ru>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Fetter <david(at)fetter(dot)org>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Oleksandr Shulgin <oleksandr(dot)shulgin(at)zalando(dot)de>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Oleg Bartunov <obartunov(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] [PATCH] Generic type subscripting
Date: 2020-09-17 12:47:54
Message-ID: CAFj8pRDuJ8n3tf_kaxd4evp3uKa8h3KA97q4GG5qRDxicbGazg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> There should be consistency
> >
> > postgres=# create table foo2(a text[]);
> > CREATE TABLE
> > postgres=# insert into foo2 values('{}');
> > INSERT 0 1
> > postgres=# update foo set a[10] = 'AHOJ';
> > UPDATE 1
> > postgres=# select (a)[10] from foo;
> > ┌────────┐
> > │ a │
> > ╞════════╡
> > │ "AHOJ" │
> > └────────┘
> > (1 row)
> >
> > and some natural behaviour - any special case with different behaviour
> is a
> > bad thing generally.
>
> Yeah, I see your point. IIRC there is no notion of an arbitrary index in
> jsonb array, so it needs to be done within an assignment operation
> similar to how the last patch fills the gaps between elements. Taking
> into account, that if there are more than one elements in the array, all
> the gaps should be filled and the behaviour is already the same as you
> described, what needs to be changed is more nulls need to be added
> around before the first element depending on the assignment index.
>

> I have my concerns about the performance side of this implementation as
> well as how surprising this would be for users, but at the same time the
> patch already does something similar and the code change should not be
> that big, so why not - I can include this change into the next rebased
> version. But it still can cause some confusion as it's not going to work
> for negative indices, so
>
> update foo set a[-10] = 1;
>
> and
>
> select a[-10] from foo;
>
> can return different value from what was assigned. Otherwise, if we will
> try to fix a[-10] assignment in the same way, it will prepend the array
> and a[10] will not return the same value.
>

What is semantic of negative index? It has clean semantic in C, but in
PLpgSQL?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2020-09-17 12:51:59 Re: Fix for parallel BTree initialization bug
Previous Message Alvaro Herrera 2020-09-17 12:40:20 Re: Command statistics system (cmdstats)