Обсуждение: integer[] Update Questions
Greeting Hackers! Had some questions about integer array type...
If I have a integer[] field in a table, which already has the values
{1,2,3,6,17} and I additionally want to add the value '45' to this
array, is there any easier way than SELECTing the current values and
then updating the entire record?
I see that I could do:
UPDATE table SET array_field[6] = 45 WHERE ...
But how do I know that 6 is the correct index without first SELECTing
all the data?
Is there an array push/pop function? Is there a method of counting the
number of integers in an array?
Thanks for any help you can provide - indexable integer arrays are an
incredible feature, thanks for the hard work!
Ryan Mahoney
Well, CVS version (7.3) of contrib/intarray has:
FUNCTIONS:
int icount(int[]) - the number of elements in intarray
int[] sort(int[], 'asc' | 'desc') - sort intarray
int[] sort(int[]) - sort in ascending order
int[] sort_asc(int[]),sort_desc(int[]) - shortcuts for sort
int[] uniq(int[]) - returns unique elements
int idx(int[], int item) - returns index of first intarray matching element to item, or
'0' if matching failed.
int[] subarray(int[],int START [, int LEN]) - returns part of intarray starting from
element number START (from 1) and length LEN.
OPERATIONS:
int[] && int[] - overlap - returns TRUE if arrays has at least one common elements.
int[] @ int[] - contains - returns TRUE if left array contains right array
int[] ~ int[] - contained - returns TRUE if left array is contained in right array
# int[] - return the number of elements in array
int[] + int - push element to array ( add to end of array)
int[] + int[] - merge of arrays (right array added to the end of left one)
int[] - int - remove entries matched by right argument from array
int[] - int[] - remove left array from right
int[] | int - returns intarray - union of arguments
int[] | int[] - returns intarray as a union of two arrays
int[] & int[] - returns intersection of arrays
I don't remember if I have a patch for 7.2
Oleg
On 23 Aug 2002, Ryan Mahoney wrote:
> Greeting Hackers! Had some questions about integer array type...
>
> If I have a integer[] field in a table, which already has the values
> {1,2,3,6,17} and I additionally want to add the value '45' to this
> array, is there any easier way than SELECTing the current values and
> then updating the entire record?
>
> I see that I could do:
> UPDATE table SET array_field[6] = 45 WHERE ...
>
> But how do I know that 6 is the correct index without first SELECTing
> all the data?
>
> Is there an array push/pop function? Is there a method of counting the
> number of integers in an array?
>
> Thanks for any help you can provide - indexable integer arrays are an
> incredible feature, thanks for the hard work!
>
> Ryan Mahoney
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83
Wow Oleg, that's great to hear! I am compiling 7.3 from CVS right now.
If you do have a patch for 7.2 could you send that - I would like to use
these functions on some production machines running 7.2.1 currently.
Thanks for the prompt response and keep up the great work!
Ryan Mahoney
On Fri, 2002-08-23 at 12:40, Oleg Bartunov wrote:
> Well, CVS version (7.3) of contrib/intarray has:
> FUNCTIONS:
>
> int icount(int[]) - the number of elements in intarray
> int[] sort(int[], 'asc' | 'desc') - sort intarray
> int[] sort(int[]) - sort in ascending order
> int[] sort_asc(int[]),sort_desc(int[]) - shortcuts for sort
> int[] uniq(int[]) - returns unique elements
> int idx(int[], int item) - returns index of first intarray matching element to item, or
> '0' if matching failed.
> int[] subarray(int[],int START [, int LEN]) - returns part of intarray starting from
> element number START (from 1) and length LEN.
>
> OPERATIONS:
>
>
> int[] && int[] - overlap - returns TRUE if arrays has at least one common elements.
> int[] @ int[] - contains - returns TRUE if left array contains right array
> int[] ~ int[] - contained - returns TRUE if left array is contained in right array
> # int[] - return the number of elements in array
> int[] + int - push element to array ( add to end of array)
> int[] + int[] - merge of arrays (right array added to the end of left one)
> int[] - int - remove entries matched by right argument from array
> int[] - int[] - remove left array from right
> int[] | int - returns intarray - union of arguments
> int[] | int[] - returns intarray as a union of two arrays
> int[] & int[] - returns intersection of arrays
>
>
> I don't remember if I have a patch for 7.2
>
> Oleg
> On 23 Aug 2002, Ryan Mahoney wrote:
>
> > Greeting Hackers! Had some questions about integer array type...
> >
> > If I have a integer[] field in a table, which already has the values
> > {1,2,3,6,17} and I additionally want to add the value '45' to this
> > array, is there any easier way than SELECTing the current values and
> > then updating the entire record?
> >
> > I see that I could do:
> > UPDATE table SET array_field[6] = 45 WHERE ...
> >
> > But how do I know that 6 is the correct index without first SELECTing
> > all the data?
> >
> > Is there an array push/pop function? Is there a method of counting the
> > number of integers in an array?
> >
> > Thanks for any help you can provide - indexable integer arrays are an
> > incredible feature, thanks for the hard work!
> >
> > Ryan Mahoney
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> >
>
> Regards,
> Oleg
> _____________________________________________________________
> Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
> Sternberg Astronomical Institute, Moscow University (Russia)
> Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
> phone: +007(095)939-16-83, +007(095)939-23-83
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
Well, we think beta is starting in 8 days, so you could be an _early_
beta tester.
---------------------------------------------------------------------------
Ryan Mahoney wrote:
> Wow Oleg, that's great to hear! I am compiling 7.3 from CVS right now.
> If you do have a patch for 7.2 could you send that - I would like to use
> these functions on some production machines running 7.2.1 currently.
>
> Thanks for the prompt response and keep up the great work!
>
> Ryan Mahoney
>
> On Fri, 2002-08-23 at 12:40, Oleg Bartunov wrote:
> > Well, CVS version (7.3) of contrib/intarray has:
> > FUNCTIONS:
> >
> > int icount(int[]) - the number of elements in intarray
> > int[] sort(int[], 'asc' | 'desc') - sort intarray
> > int[] sort(int[]) - sort in ascending order
> > int[] sort_asc(int[]),sort_desc(int[]) - shortcuts for sort
> > int[] uniq(int[]) - returns unique elements
> > int idx(int[], int item) - returns index of first intarray matching element to item, or
> > '0' if matching failed.
> > int[] subarray(int[],int START [, int LEN]) - returns part of intarray starting from
> > element number START (from 1) and length LEN.
> >
> > OPERATIONS:
> >
> >
> > int[] && int[] - overlap - returns TRUE if arrays has at least one common elements.
> > int[] @ int[] - contains - returns TRUE if left array contains right array
> > int[] ~ int[] - contained - returns TRUE if left array is contained in right array
> > # int[] - return the number of elements in array
> > int[] + int - push element to array ( add to end of array)
> > int[] + int[] - merge of arrays (right array added to the end of left one)
> > int[] - int - remove entries matched by right argument from array
> > int[] - int[] - remove left array from right
> > int[] | int - returns intarray - union of arguments
> > int[] | int[] - returns intarray as a union of two arrays
> > int[] & int[] - returns intersection of arrays
> >
> >
> > I don't remember if I have a patch for 7.2
> >
> > Oleg
> > On 23 Aug 2002, Ryan Mahoney wrote:
> >
> > > Greeting Hackers! Had some questions about integer array type...
> > >
> > > If I have a integer[] field in a table, which already has the values
> > > {1,2,3,6,17} and I additionally want to add the value '45' to this
> > > array, is there any easier way than SELECTing the current values and
> > > then updating the entire record?
> > >
> > > I see that I could do:
> > > UPDATE table SET array_field[6] = 45 WHERE ...
> > >
> > > But how do I know that 6 is the correct index without first SELECTing
> > > all the data?
> > >
> > > Is there an array push/pop function? Is there a method of counting the
> > > number of integers in an array?
> > >
> > > Thanks for any help you can provide - indexable integer arrays are an
> > > incredible feature, thanks for the hard work!
> > >
> > > Ryan Mahoney
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 4: Don't 'kill -9' the postmaster
> > >
> >
> > Regards,
> > Oleg
> > _____________________________________________________________
> > Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
> > Sternberg Astronomical Institute, Moscow University (Russia)
> > Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
> > phone: +007(095)939-16-83, +007(095)939-23-83
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
-- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610)
359-1001+ If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square,
Pennsylvania19073
On 23 Aug 2002, Ryan Mahoney wrote:
> Wow Oleg, that's great to hear! I am compiling 7.3 from CVS right now.
> If you do have a patch for 7.2 could you send that - I would like to use
> these functions on some production machines running 7.2.1 currently.
unfortuneately, we don't have a *reliable* patch for 7.2 :-(
but Beta is started (should) very soon, so you'd be able to test your
real life application :0
Oleg
>
> Thanks for the prompt response and keep up the great work!
>
> Ryan Mahoney
>
> On Fri, 2002-08-23 at 12:40, Oleg Bartunov wrote:
> > Well, CVS version (7.3) of contrib/intarray has:
> > FUNCTIONS:
> >
> > int icount(int[]) - the number of elements in intarray
> > int[] sort(int[], 'asc' | 'desc') - sort intarray
> > int[] sort(int[]) - sort in ascending order
> > int[] sort_asc(int[]),sort_desc(int[]) - shortcuts for sort
> > int[] uniq(int[]) - returns unique elements
> > int idx(int[], int item) - returns index of first intarray matching element to item, or
> > '0' if matching failed.
> > int[] subarray(int[],int START [, int LEN]) - returns part of intarray starting from
> > element number START (from 1) and length LEN.
> >
> > OPERATIONS:
> >
> >
> > int[] && int[] - overlap - returns TRUE if arrays has at least one common elements.
> > int[] @ int[] - contains - returns TRUE if left array contains right array
> > int[] ~ int[] - contained - returns TRUE if left array is contained in right array
> > # int[] - return the number of elements in array
> > int[] + int - push element to array ( add to end of array)
> > int[] + int[] - merge of arrays (right array added to the end of left one)
> > int[] - int - remove entries matched by right argument from array
> > int[] - int[] - remove left array from right
> > int[] | int - returns intarray - union of arguments
> > int[] | int[] - returns intarray as a union of two arrays
> > int[] & int[] - returns intersection of arrays
> >
> >
> > I don't remember if I have a patch for 7.2
> >
> > Oleg
> > On 23 Aug 2002, Ryan Mahoney wrote:
> >
> > > Greeting Hackers! Had some questions about integer array type...
> > >
> > > If I have a integer[] field in a table, which already has the values
> > > {1,2,3,6,17} and I additionally want to add the value '45' to this
> > > array, is there any easier way than SELECTing the current values and
> > > then updating the entire record?
> > >
> > > I see that I could do:
> > > UPDATE table SET array_field[6] = 45 WHERE ...
> > >
> > > But how do I know that 6 is the correct index without first SELECTing
> > > all the data?
> > >
> > > Is there an array push/pop function? Is there a method of counting the
> > > number of integers in an array?
> > >
> > > Thanks for any help you can provide - indexable integer arrays are an
> > > incredible feature, thanks for the hard work!
> > >
> > > Ryan Mahoney
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 4: Don't 'kill -9' the postmaster
> > >
> >
> > Regards,
> > Oleg
> > _____________________________________________________________
> > Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
> > Sternberg Astronomical Institute, Moscow University (Russia)
> > Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
> > phone: +007(095)939-16-83, +007(095)939-23-83
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
Regards, Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83