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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dirk Mika <Dirk(dot)Mika(at)mikatiming(dot)de>
Cc: "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-02 13:52:57
Message-ID: 30905.1562075577@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dirk Mika <Dirk(dot)Mika(at)mikatiming(dot)de> writes:
> But when I try to modify a field of a record in the array I get a syntax error.
> l_classes_array[i].field1 := l_value;
> The error is ERROR: syntax error at or near "." Position: 12414 where position points to the . after the [i]. I've no idea what's causing this syntax error.

Yeah, that seems like it ought to work, and ideally it would. But plpgsql
doesn't currently have support for nested field-of-array-element or
element-of-record-field assignments. (I've looked briefly at this in the
past, and it doesn't seem impossible, but it's definitely not trivial
either.)

You'll have to do some kind of workaround like assigning the whole array
element to a temp variable, fixing the field in the temp variable, then
assigning back :-(

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrien Nayrat 2019-07-02 16:45:17 Re: Statistics tables not being updated anymore
Previous Message Adrian Klaver 2019-07-02 13:36:13 Re: Statistics tables not being updated anymore