2

I need to append an item to existed array in postgresql. I wrote this code (plpgsql function):

perform array_append (arrayA::integer[],id);

Since it didn't work I tried:

raise notice '%', arrayA;
perform array_append (arrayA::integer[],id);
raise notice '%', arrayA;

It gives:

NOTICE:  <NULL>
NOTICE:  <NULL>

Why the array isn't updated?

1
  • 1
    v_arraya := arraya || id or v_array := array_append(arraya, id); (that assumes that the variable arrraya is indeed an array Commented Dec 17, 2015 at 14:38

1 Answer 1

5

PERFORM query discard the results. array_append doesn't update the array you specify in the first parameter. It only reads the its values.

You should change your code to:

select array_append (arrayA::integer[],id) into v_arrayA;
Sign up to request clarification or add additional context in comments.

1 Comment

The select is not necessary, you can just assign the result to the variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.