targetted array element modification or delete without knowing the index?
targetted array element modification or delete without knowing the index?
От:
"Gauthier, Dave" <dave.gauthier@intel.com>
Дата:
Is there a way to modify or delete an element of an array with knowledge only of the element’s value? Maybe an array index finder would help?
For example
create table foo (name,text, arr text[]);
insert into foo (name,arr) values (‘joe’,ARRAY[‘a’,’b’,’c’]);
update foo set arr[indexfinder(‘b’)] = ‘z’;
This would update arr[2], because that’s the element with value ‘b’
Thanks !
Re: targetted array element modification or delete without knowing the index?
От:
Richard Broersma <richard.broersma@gmail.com>
Дата:
On Thu, Dec 24, 2009 at 10:01 AM, Gauthier, Dave wrote: > Is there a way to modify or delete an element of an array with knowledge > only of the element’s value? Maybe an array index finder would help? I haven't tried it myself, but would the array "contains" operator work for you? http://www.postgresql.org/docs/8.4/static/functions-array.html#ARRAY-OPERATORS-TABLE -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug