Re: plpgsql: How to modify a field in an array of records

From: Dirk Mika <Dirk(dot)Mika(at)mikatiming(dot)de>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: plpgsql: How to modify a field in an array of records
Date: 2019-07-03 05:04:33
Message-ID: 75F7E98B-BD0A-40DE-8C89-0C01BDA7EC90@mikatiming.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--
Dirk Mika
Software Developer

mika:timing GmbH
Strundepark - Kürtener Str. 11b
51465 Bergisch Gladbach
Germany

fon +49 2202 2401-1197
dirk(dot)mika(at)mikatiming(dot)de
www.mikatiming.de

AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884
Geschäftsführer: Harald Mika, Jörg Mika

## How2Use
## the ChampionChip by mika:timing
## https://youtu.be/qfOFXrpSKLQ
Am 03.07.19, 01:39 schrieb "raf(at)raf(dot)org" <raf(at)raf(dot)org>:

If the problem you are facing is similar in nature, you
might be able to work around it by having a variable of
the same type as the array elements, assign to it the
record that you want to modify, make the modification
in the single record variable and then assign that
single record variable back into the array element that
it came from.

i.e. something like:

declare
a rectype[];
r rectype;
i integer;
begin
...
r := a[i];
r.field := newvalue;
a[i] := r;
...

It actually works the way you suggested. Not nice, but as long as it works, it's ok ;-)

I didn't even realise that you could have an array of records.
I've only ever used arrays of scalar values.

Yes, if that wasn't possible, I would have had to switch to a series of Array of scalar values.

BR
Dirk

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vijaykumar Jain 2019-07-03 05:27:43 multiple nodes in FDW create server statement
Previous Message Dirk Mika 2019-07-03 04:53:28 Re: plpgsql: How to modify a field in an array of records