0

This statement is throwing error:

FOR _i2 IN 1 .. array_upper(p_extra_info, 1) LOOP
    ....
    SELECT currval('ad_extra_info_id_seq') INTO _new_extra_info_ids[_i2];
    ....
END LOOP;

ERROR:  syntax error at or near "["
LINE 179: ...rrval('ad_extra_info_id_seq') INTO _new_extra_info_ids[_i2];
                                                                   ^
********** Error **********

ERROR: syntax error at or near "["
SQL state: 42601
Character: 7907

Variable _new_extra_info_ids is declared like this: _new_extra_info_ids integer[];

Do you know what is wrong?

3
  • Firstly one recommendation Please do not declare any variable name starting with special Character some times I faced the compiler get confused with this kind of naming convention. Commented Oct 13, 2016 at 6:19
  • I put '_' in front of all declared variables for distinction - never given me trouble. @a_horse_with_no_name that works, thanks. Commented Oct 13, 2016 at 6:28
  • 1
    Doing stuff like that in loops might indicate some inefficient handling of sets in your function. You might want to revisit that logic - but there is not enough information to really say that. But seeing a select inside a loop usually rings an alarm bell for me. Commented Oct 13, 2016 at 6:40

1 Answer 1

1

Use a direct assignment instead of a select:

FOR _i2 IN 1 .. array_upper(p_extra_info, 1) LOOP
    ....
    _new_extra_info_ids[_i2] := currval('ad_extra_info_id_seq');
    ....
END LOOP;
Sign up to request clarification or add additional context in comments.

Comments

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.