0

I have a multidimensional array like this one:

coeficiente VARCHAR[2][2];

What i have stored in this array is this information:

{{"uwu","2"},{"owo","5"}}

I have another 2 variables called:

variable1 VARCHAR;
variable2 VARCHAR;

I want to save the "2" into the variable1, and the "5" into variable2 from this multidimensional array content example.

How can i do that?

I was thinking in maybe a for loop, but i still dunno how iterate inside of an ARRAY[][] structure in plpgsql.

The closest examples I could reach in internet were:

stack overflow. But they store an array out of a multidimensional array. I only need to get the variable inside of it.

Postgres documentation. But it doesn't explain how to get inside of one specific "slot".

2 Answers 2

1

Maybe I am missing something, but:

variable1 := coeficiente[1][2];
variable2 := coeficiente[2][2];

will do what you want.

do
$$
declare
  coeficiente VARCHAR[2][2] := '{{"uwu","2"},{"owo","5"}}';
  variable1 VARCHAR;
  variable2 VARCHAR;  
begin
  variable1 := coeficiente[1][2];
  variable2 := coeficiente[2][2];
  
  raise notice 'var1=%', variable1;
  raise notice 'var2=%', variable2;
end;
$$  

Will output:

var1=2
var2=5
Sign up to request clarification or add additional context in comments.

Comments

0

You can loop over a two-dimensional array by using two for loops, also known as nested loop. Similarly to loop an n-dimensional array you need n loops nested into each other.

1 Comment

Yes but how can I move inside of it and assign that information into my variable? variable1:=coeficiente[1][2] for exampe?

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.