pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dirk Mika <Dirk.Mika@mikatiming.de>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: plpgsql: How to modify a field in an array of records
Date: Tue, 02 Jul 2019 09:52:57 -0400
Message-ID: <30905.1562075577@sss.pgh.pa.us> (raw)
In-Reply-To: <A3691E98-CCA5-4DEB-B43C-92AD0437E09E@mikatiming.de>
References: <A3691E98-CCA5-4DEB-B43C-92AD0437E09E@mikatiming.de>

Dirk Mika <Dirk.Mika@mikatiming.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





view thread (5+ messages)  latest in thread

Message-ID: <30905.1562075577@sss.pgh.pa.us>
Permalink:  ../30905.1562075577@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/30905.1562075577@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Dirk.Mika@mikatiming.de
  Subject: Re: plpgsql: How to modify a field in an array of records
  In-Reply-To: <30905.1562075577@sss.pgh.pa.us>
  References: <A3691E98-CCA5-4DEB-B43C-92AD0437E09E@mikatiming.de> <30905.1562075577@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox