title: Postgres Function to Insert Arrays
body: <p>I am trying to INSERT data via a postgres function, and I can't quite get it working. I am getting an error stating </p>
  
  <blockquote>
    <p>ERROR: function unnest(integer) does not exist
    SQL state: 42883
    Hint: No function matches the given name and argument types. You might need to add explicit type casts.</p>
  </blockquote>
  
  <p>I am using Postgres 9.5, and my function is as follows:</p>
  
  <pre><code>CREATE FUNCTION insert_multiple_arrays(
  some_infoid INTEGER[],
  other_infoid INTEGER[],
  some_user_info VARCHAR,
  OUT new_user_id INTEGER
  )
  RETURNS INTERGER AS $$
  BEGIN
  INSERT INTO user_table (user_info) VALUES ($3) RETURNING user_id INTO new_user_id;
  INSERT INTO some_info_mapper (user_id, some_info_id) SELECT new_user_id, unnest($1);
  INSERT INTO other_info_mapper (user_id, other_info_id) SELECT  new_user_id,unnest($2);
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>I will be calling the stored procedure from my backend via a SELECT statement. An example is like so:</p>
  
  <pre><code>createUser(user, callback){
      let client = this.getDb();
      client.query("SELECT insert_multiple_arrays($1, $2, $3)",
          [user.some_info_ids, user.other_info_ids, user.info], function(err, results){
          if(err){
              callback (err);
          }
          callback(null, results);
      });
  };
  </code></pre>
  
  <p>The output that I am expecting would be as follows:</p>
  
  <pre><code>user_table
  
     user_id            | user_info       |
  ----------------------+-----------------+
      1                 | someInfo        |
  
  
  
  some_info_mapper
  
     user_id            | some_info_id    |
  ----------------------+-----------------+
      1                 | 33              |
      1                 | 5               |
  
  
  other_info_mapper
  
     user_id            | other_info_id   |
  ----------------------+-----------------+
      1                 | 8               |
      1                 | 9               |
      1                 | 22              |
      1                 | 66              |   
      1                 | 99              |   
  </code></pre>
  
  <p>How do I handle this error? Do I need to do some sort of processing to my data to put it into a format that postgres accepts?</p>