Re: Questions about setting an array element value outside of the update

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Johnston <polobo(at)yahoo(dot)com>
Cc: Maxim Boguk <maxim(dot)boguk(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Questions about setting an array element value outside of the update
Date: 2011-12-05 04:13:23
Message-ID: 24332.1323058403@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David Johnston <polobo(at)yahoo(dot)com> writes:
>> Is here less clumsy way to set array[position] to the new_value (not update but just change an element inside an array) than:
>>
>> SELECT
>> _array[1:pos-1]
>> ||newval
>> ||_array[_pos+1:array_length(_array, 1)]

> I do not know if there is a cleaner way but regardless you should code
> your logic as a function.

Inside a plpgsql function, you could just do

array[pos] := newval;

so perhaps it'd be worth creating a helper function that's a wrapper
around that.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2011-12-05 04:15:28 Re: WITH and WITH RECURSIVE in single query
Previous Message Mike Christensen 2011-12-05 04:10:14 What's the best way in Postgres9 to store a bunch of arbitrary boolean values for a row?