PLPGSQL - store fetched records in array of record

From: Durumdara <durumdara(at)gmail(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: PLPGSQL - store fetched records in array of record
Date: 2025-07-02 12:21:22
Message-ID: CAEcMXhmEJjrqruc0RUSNeUiUzzCf7K_TxuUAzFZoNBi_UzQdzA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello!

I have to store some fetched records into two lists (arrays) to work with
them.

I can use the RECORD type in a FOR SELECT loop to get one row data.

declare
f record;
begin
for f in select title, length

But if I tried to define an "array of record", I got an error message.

declare
R_A record[]; <---- some error

So I can't store the fetched data into an array simply.

Ok, I found a solution when I define a TYPE, and I use this:

declare
f TMy_Record;
R_A TMy_Record[];

Then I can work with the data.

But this means a dependency, so I can't change the TYPE without
pre-dropping the stored procedure (and without recreating after).

Is there any way to avoid this? To use a "simple untyped record" in an
array without "dependencies"?

Thank you for the answer!

Best regards
dd

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2025-07-02 13:23:22 Re: PLPGSQL - store fetched records in array of record
Previous Message Amritanshu Joshi 2025-07-01 19:48:42 Fwd: Anomalous behavior between two Aurora Postgres RDS clusters