title: Getting the error "ERROR: array subscript out of range" when multiplying matrices PL/pgSQL?
body: <p>I'm traiying to code, as exercise, a PL/pgSQL function that multiplies two matrices then print the solution when called. I'm new in this language and can't find what's wrong with the code. Help!</p>
  <pre><code>CREATE OR REPLACE FUNCTION multiplicarMatrizes(matriz1 float[][], matriz2 float[][], OUT produto float[][]) AS
  $$
  DECLARE
      i integer;
      j integer;
      k integer;
  BEGIN
      
      IF array_length(matriz1, 1) &lt;&gt; array_length(matriz2, 2) THEN
          RAISE EXCEPTION 'O número de linhas da matriz 1 deve ser igual ao número de colunas da matriz 2';
      END IF;
  
      FOR i IN 1..array_length(matriz1, 1) LOOP
          FOR j IN 1..array_length(matriz2, 2) LOOP
              FOR k IN 1..array_length(matriz1, 1) LOOP
                  produto[i][j] = produto[i][j] + matriz1[i][k] * matriz2[k][j];
              END LOOP;
          END LOOP;
      END LOOP;
  
  END;
  $$ language plpgsql;
  
  
  SELECT multiplicarMatrizes('{{1.0,2.0}, {2.0,1.0}}', '{{1.0,0.0},{0.0,1.0}}'); // CALLING THE FUNCTION
  </code></pre>
  <p>As result, I'm getting the error:</p>
  <pre><code>[44:1] Failed in 0 s.
  [Exception, Error code 0, SQLState 2202E] ERROR: array subscript out of range
    Onde: função PL/pgSQL multiplicarmatrizes(double precision[],double precision[]) linha 15 em atribuição
    Line 44, column 1
  </code></pre>
  <p>Can anyone help, please?!</p>