Re: Out of memory error - Mailing list pgsql-performance

From Thomas Kellerer
Subject Re: Out of memory error
Date
Msg-id f8952c15-6cde-2a0a-b095-cfedd34ba734@gmx.net
Whole thread Raw
In response to Re: Out of memory error  (aditya desai <admad123@gmail.com>)
List pgsql-performance
aditya desai schrieb am 24.11.2021 um 08:31:
> H Michael,
> Please see insert_info function below. Also r_log_message is composite data type and it's definition is also given
below.
>
> CREATE OR REPLACE FUNCTION insert_info(
>     info_array  r_log_message[]
> ) RETURNS varchar AS $$
>     DECLARE
>         info_element  r_log_message;
>     BEGIN
>         FOREACH info_element IN ARRAY info_array
>         LOOP
>             INSERT INTO testaditya(
>                 columname,
>                 oldvalue,
>                 newvalue
>             ) VALUES(
>                 info_element.column_name,
>                 info_element.oldvalue,
>                 info_element.newvalue
>             );
>         END LOOP;
>         RETURN 'OK';
>     END;
> $$ LANGUAGE plpgsql;

You don't need a loop for that. This can be done more efficiently using unnest()


    INSERT INTO testaditya(columname,oldvalue,newvalue)
    select u.*
    from unnest(info_array) as u;






pgsql-performance by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Out of memory error
Next
From: Tomas Vondra
Date:
Subject: Re: Postgres process count GCC vs Clang is Different on autovaccum=on