Re: How to set array element to null value

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Brahmam Eswar <brahmam1234(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to set array element to null value
Date: 2018-07-09 10:26:46
Message-ID: CAFj8pRAJCyJF0VAuwW1V6sDgi0mY+c61_n-SWf=GkaYtYuk=9Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

2018-07-09 11:58 GMT+02:00 Brahmam Eswar <brahmam1234(at)gmail(dot)com>:

> I'm trying to reset array element to null. but 3rd line of below snippet
> is giving the compilation error.
>
>
> FOR indx_1 IN array_lower(X, 1)..array_upper(X, 1) LOOP
> IF X[indx_1].REFERENCE_VALUE = 'ABC' THEN
> X[indx_1].REFERENCE_VALUE:='';
> END IF;
> END LOOP;
>
>
a) plpgsql doesn't support complex expressions on left side of assign
command, b) '' is not NULL in PostgreSQL

you can write your code some like

DECLARE r RECORD;
BEGIN
FOR i IN array_lower(x, 1) .. array_upper(x, 1)
LOOP
r := x[i];
IF r.reference_value = 'ABC' THEN
r.reference_value := NULL;
x[i] := r;
END IF;
END LOOP;
END;

Regards

Pavel

> --
> Thanks & Regards,
> Brahmeswara Rao J.
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2018-07-09 10:29:44 Re: How to set array element to null value
Previous Message Brahmam Eswar 2018-07-09 09:58:45 How to set array element to null value

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Kellerer 2018-07-09 10:29:44 Re: How to set array element to null value
Previous Message Simon Riggs 2018-07-09 10:00:51 Allowing multiple DDL commands to run simultaneously