jsonb_set for an array with an index outside of boundaries

Поиск
Список
Период
Сортировка
От Dmitry Dolgov
Тема jsonb_set for an array with an index outside of boundaries
Дата
Msg-id CA+q6zcUgeNJxZrc3K7LQhAS7NYOqz5+xYyDsggjrpDxVK203KQ@mail.gmail.com
обсуждение исходный текст
Список pgsql-hackers
Hi,

Per discussion in [1] about generic type subscripting pathc Pavel had
interesting commentary. So far jsonb_set, if is invoked for a jsonb array with
an index outside of the array boundaries, will implicitely add a value:

=# insert into table values('["a", "b", "c"]');
=# update table set data = jsonb_set(data, '{1000}', '"d"');
=# table test;
=# table test;
data
----------------------
["a", "b", "c", "d"]

This is perfectly documented feature, there are no questions here. But for
generic type subscripting infrastructure I'm introducing another, more
convenient, syntax:

=# update table test set data['selector'] = 'value';

Since the idea behind generic type subsripting patch is just to introduce
extendable subscripting operation for different data types, here I'm relying on
already existing functionality for jsonb. But then this feature of jsonb_set
indeed became more confusing with the new syntax.

=# update table test set data[1000] = 'd';
=# table test;
data
----------------------
["a", "b", "c", "d"]

Unfortunately, the only alternative option here would be to return an error and
reject such a value, which differs from jsonb_set. I would like to ask , what
would be the best solution here - to keep this confusing behaviour, or to have
two different implementation of updating jsonb functionality (one for
jsonb_set, another for subscripting)?

[1]: https://www.postgresql.org/message-id/CA%2Bq6zcXmwR9BDrcf188Mcz5%2BjU8DaqrrOat2mzizKf-nYgDXkg%40mail.gmail.com


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Dmitry Dolgov
Дата:
Сообщение: Re: ArchiveEntry optional arguments refactoring
Следующее
От: David Rowley
Дата:
Сообщение: Re: [HACKERS] PATCH: multivariate histograms and MCV lists