Some questions about the array.
We were some of the issues associated with the behavior of arrays.
1. We would like to implement arrays negative indices (from the end) like in
Python or Ruby: arr[-2] or arr[1: -1]
but as an array can be indexed in the negative area so it probably can not be
done.
2. We would like to add the ability be omitted boundaries in the slice.
Example: arr[2:] or arr[:2]. But there was a problem with the update of an
empty array:
arr[1:][1:] = {1,2,3,4,5,6} can be interpreted as
arr[1:3][1:2] or arr[1:2] [1:3] or [1:1], [1:6]
What is the history of the emergence of such arrays? Maybe something can be
improved?
P.S. I would like List datatype as in Python. Is there any fundamental
objections? Or we just did not have the time and enthusiasm before?
The current implementation I would call vectors or matrices but not arrays.
IMHO
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 10/09/2015 08:02 AM, YUriy Zhuravlev wrote:
We were some of the issues associated with the behavior of arrays.
1. We would like to implement arrays negative indices (from the end) like in
Python or Ruby: arr[-2] or arr[1: -1]
but as an array can be indexed in the negative area so it probably can not be
done.
2. We would like to add the ability be omitted boundaries in the slice.
Example: arr[2:] or arr[:2]. But there was a problem with the update of an
empty array:
arr[1:][1:] = {1,2,3,4,5,6} can be interpreted as
arr[1:3][1:2] or arr[1:2] [1:3] or [1:1], [1:6]What is the history of the emergence of such arrays? Maybe something can be
improved?P.S. I would like List datatype as in Python. Is there any fundamental
objections? Or we just did not have the time and enthusiasm before?
The current implementation I would call vectors or matrices but not arrays.
IMHO
The name array is now far too baked in to change it.
jsonb and json arrays have many of the characteristics you seem to want.
They are always 0-based and negative indexes count from the end. They
also don't have to be regular, unlike our native arrays.
cheers
andrew
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Fri, Oct 9, 2015 at 6:27 PM, Andrew Dunstan <andrew@dunslane.net> wrote:
On 10/09/2015 08:02 AM, YUriy Zhuravlev wrote:
We were some of the issues associated with the behavior of arrays.
1. We would like to implement arrays negative indices (from the end) like
in
Python or Ruby: arr[-2] or arr[1: -1]
but as an array can be indexed in the negative area so it probably can
not be
done.
2. We would like to add the ability be omitted boundaries in the slice.
Example: arr[2:] or arr[:2]. But there was a problem with the update of an
empty array:
arr[1:][1:] = {1,2,3,4,5,6} can be interpreted as
arr[1:3][1:2] or arr[1:2] [1:3] or [1:1], [1:6]What is the history of the emergence of such arrays? Maybe something can
be
improved?P.S. I would like List datatype as in Python. Is there any fundamental
objections? Or we just did not have the time and enthusiasm before?
The current implementation I would call vectors or matrices but not
arrays.
IMHOThe name array is now far too baked in to change it.
jsonb and json arrays have many of the characteristics you seem to want.
They are always 0-based and negative indexes count from the end. They also
don't have to be regular, unlike our native arrays.
jsonb and json arrays support very limited number of types. Casting other
datatypes to/from text is an option, but it is both awkward and not
space-compact.
Omitted boundaries in the slice looks nice for me. Considering problem with
empty array, current behaviour of empty array updating doesn't look
consistent for me.
When updating non-empty array its boundaries isn't extending. If one update
non-empty array out of its boundaries then he get an error "ERROR: array
subscript out of range".
If we extrapolate this logic to empty arrays then we this error should be
thrown on any update of empty array. Despite this, we allow any update of
empty array.
------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
On Fri, Oct 9, 2015 at 8:02 AM, YUriy Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:
We were some of the issues associated with the behavior of arrays.
1. We would like to implement arrays negative indices (from the end) like in
Python or Ruby: arr[-2] or arr[1: -1]
but as an array can be indexed in the negative area so it probably can not be
done.
That seems like a complete non-starter because it would break backward
compatibility. Our array implementation allows negative indexes:
rhaas=# select ('[-1:4]={3,1,4,1,5,9}'::int[])[-1];
int4
------
3
(1 row)
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello again.
I attached simple patch for omitted boundaries in the slice.
This will simplify the writing of SQL. Instead:
select arr[2:array_upper(arr, 1)];
you can write:
select arr[2:];
simple and elegant.
Omitted boundaries is prohibited in UPDATE.
Thanks.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Attachments:
extend_slice_v2.patchtext/x-patch; charset=UTF-8; name=extend_slice_v2.patchDownload+161-25
Hello hackers.
There are comments to my patch? Maybe I should create a separate thread?
Thanks.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Thu, Nov 5, 2015 at 9:57 AM, YUriy Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:
Hello hackers.
There are comments to my patch? Maybe I should create a separate thread?
Thanks.
You should add this on commitfest.postgresql.org.
I think the first question that needs to be answered is "do we want
this?". I'm sure I know your answer, but what do other people think?
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 6 November 2015 at 12:45, Robert Haas <robertmhaas@gmail.com> wrote:
On Thu, Nov 5, 2015 at 9:57 AM, YUriy Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:Hello hackers.
There are comments to my patch? Maybe I should create a separate thread?
Thanks.You should add this on commitfest.postgresql.org.
I think the first question that needs to be answered is "do we want
this?". I'm sure I know your answer, but what do other people think?
Omitted bounds are common in other languages and would be handy. I
don't think they'd cause any issues with multi-dimensional arrays or
variable start-pos arrays.
I'd love negative indexes, but the variable-array-start (mis)feature
means we can't have those. I wouldn't shed a tear if
variable-start-position arrays were deprecated and removed, but that's
a multi-year process, and I'm not convinced negative indexes justify
it even though the moveable array start pos feature seems little-used.
Since the start-pos is recorded in the array, I wonder if it's worth
supporting negative indexing for arrays with the default 1-indexed
element numbering, and just ERRORing for others. Does anyone really
use anything else?
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Thursday, November 5, 2015, Craig Ringer <craig@2ndquadrant.com> wrote:
On 6 November 2015 at 12:45, Robert Haas <robertmhaas@gmail.com
<javascript:;>> wrote:On Thu, Nov 5, 2015 at 9:57 AM, YUriy Zhuravlev
<u.zhuravlev@postgrespro.ru <javascript:;>> wrote:Hello hackers.
There are comments to my patch? Maybe I should create a separate thread?
Thanks.You should add this on commitfest.postgresql.org.
I think the first question that needs to be answered is "do we want
this?". I'm sure I know your answer, but what do other people think?Omitted bounds are common in other languages and would be handy. I
don't think they'd cause any issues with multi-dimensional arrays or
variable start-pos arrays.I'd love negative indexes, but the variable-array-start (mis)feature
means we can't have those. I wouldn't shed a tear if
variable-start-position arrays were deprecated and removed, but that's
a multi-year process, and I'm not convinced negative indexes justify
it even though the moveable array start pos feature seems little-used.Since the start-pos is recorded in the array, I wonder if it's worth
supporting negative indexing for arrays with the default 1-indexed
element numbering, and just ERRORing for others. Does anyone really
use anything else?
Does it have to be "negative"?
Would something like array[1:~1] as a syntax be acceptable to denote
backward counting?
David J.
On Thursday 05 November 2015 22:33:37 you wrote:
Would something like array[1:~1] as a syntax be acceptable to denote
backward counting?
Very interesting idea! I could implement it. I just need to check for side
effects.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Thursday 05 November 2015 23:45:53 you wrote:
On Thu, Nov 5, 2015 at 9:57 AM, YUriy Zhuravlev
<u.zhuravlev@postgrespro.ru> wrote:
Hello hackers.
There are comments to my patch? Maybe I should create a separate thread?
Thanks.You should add this on commitfest.postgresql.org.
I created a couple of weeks ago:
https://commitfest.postgresql.org/7/397/
I'm sure I know your answer, but what do other people think?
I wonder the same thing.
Thanks.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 11/5/15 10:55 PM, Craig Ringer wrote:
Omitted bounds are common in other languages and would be handy. I
don't think they'd cause any issues with multi-dimensional arrays or
variable start-pos arrays.
+1
I'd love negative indexes, but the variable-array-start (mis)feature
means we can't have those. I wouldn't shed a tear if
variable-start-position arrays were deprecated and removed, but that's
a multi-year process, and I'm not convinced negative indexes justify
it even though the moveable array start pos feature seems little-used.
I'm all for ditching variable start, full stop.
Since the start-pos is recorded in the array, I wonder if it's worth
supporting negative indexing for arrays with the default 1-indexed
element numbering, and just ERRORing for others. Does anyone really
use anything else?
I'd prefer that over using something like ~.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Fri, Nov 6, 2015 at 9:44 PM, Jim Nasby <Jim.Nasby@bluetreble.com> wrote:
Since the start-pos is recorded in the array, I wonder if it's worth
supporting negative indexing for arrays with the default 1-indexed
element numbering, and just ERRORing for others. Does anyone really
use anything else?I'd prefer that over using something like ~.
I'm not necessarily objecting to that, but it's not impossible that it
could break something for some existing user. We can decide not to
care about that, though.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Sunday 08 November 2015 16:49:20 you wrote:
I'm not necessarily objecting to that, but it's not impossible that it
could break something for some existing user. We can decide not to
care about that, though.
We had an idea. You can use ~ to convert the index to the array which always
starts with 0. Then we can use negative indexes, and you can always find the
beginning of the array.
Example:
we have array [-3:3]={1,2,3,4,5,6,7}
array[~0] == 1
array[~-1] == 7
array[~2:~-2] == {3,4,5,6}
What do you think?
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
2015-11-09 12:36 GMT+01:00 YUriy Zhuravlev <u.zhuravlev@postgrespro.ru>:
On Sunday 08 November 2015 16:49:20 you wrote:
I'm not necessarily objecting to that, but it's not impossible that it
could break something for some existing user. We can decide not to
care about that, though.We had an idea. You can use ~ to convert the index to the array which
always
starts with 0. Then we can use negative indexes, and you can always find
the
beginning of the array.
Example:
we have array [-3:3]={1,2,3,4,5,6,7}
array[~0] == 1
array[~-1] == 7
array[~2:~-2] == {3,4,5,6}What do you think?
I am sorry - it is looking pretty obscure. Really need this feature?
Pavel
Show quoted text
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Monday 09 November 2015 12:48:54 you wrote:
I am sorry - it is looking pretty obscure. Really need this feature?
IMHO yes.
Now for write: array[~2:~-2] you need like:
array[array_lower(array, 1)+3: array_upper(array, 1)-2]
Worse when long names. Besides the extra functions calls.
Thanks.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
From: pgsql-hackers-owner@postgresql.org [mailto:pgsql-hackers-owner@postgresql.org] On Behalf Of Pavel Stehule
Sent: Montag, 9. November 2015 12:49
To: YUriy Zhuravlev
Cc: PostgreSQL Hackers
Subject: Re: [HACKERS] Some questions about the array.2015-11-09 12:36 GMT+01:00 YUriy Zhuravlev <u.zhuravlev@postgrespro.ru>:
On Sunday 08 November 2015 16:49:20 you wrote:I'm not necessarily objecting to that, but it's not impossible that it
could break something for some existing user. We can decide not to
care about that, though.We had an idea. You can use ~ to convert the index to the array which always
starts with 0. Then we can use negative indexes, and you can always find the
beginning of the array.
Example:
we have array [-3:3]={1,2,3,4,5,6,7}
array[~0] == 1
array[~-1] == 7
array[~2:~-2] == {3,4,5,6}What do you think?
Hi,
~ is the bitwise NOT operator.
so array[~n:~m] has a current meaning. Not very useful though.
It would be better to choose another character.
my 2 pence,
Marc Mamin
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
2015-11-09 13:07 GMT+01:00 YUriy Zhuravlev <u.zhuravlev@postgrespro.ru>:
On Monday 09 November 2015 12:48:54 you wrote:
I am sorry - it is looking pretty obscure. Really need this feature?
IMHO yes.
Now for write: array[~2:~-2] you need like:
array[array_lower(array, 1)+3: array_upper(array, 1)-2]Worse when long names. Besides the extra functions calls.
It is ugly, but you can wrap it to function - so still I don't see any
reason, why it is necessary
Regards
Pavel
Show quoted text
Thanks.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Monday 09 November 2015 13:29:30 you wrote:
It is ugly, but you can wrap it to function - so still I don't see any
reason, why it is necessary
For example, I'm writing a lot of queries by hands...
This functionality is available in many languages and it's just convenient. Of
course it is possible and without it, but why?
Thanks.
--
YUriy Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 11/9/15, YUriy Zhuravlev <u.zhuravlev@postgrespro.ru> wrote:
On Monday 09 November 2015 12:48:54 you wrote:
I am sorry - it is looking pretty obscure. Really need this feature?
IMHO yes.
Now for write: array[~2:~-2] you need like:
array[array_lower(array, 1)+3: array_upper(array, 1)-2]Worse when long names. Besides the extra functions calls.
You can write it as a separate function instead of changing current syntax.
Call would be like :
SELECT slice_abs('[-3:3]={1,2,3,4,5,6,7}'::int[], 2, -2) == {3,4,5,6}
SELECT slice_abs('[-3:3]={1,2,3,4,5,6,7}'::int[], 2, NULL) ==
{3,4,5,6,7} -- omitting boundaries
--
Best regards,
Vitaly Burovoy
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers