title: Inserting array of custom types into postgres
body: <p>I'm trying to insert a row with a column that is an array of a custom type (<code>ingredient</code>). My tables are:</p>
  
  <pre><code>CREATE TYPE ingredient AS (
      name text,
      quantity text,
      unit text
  );
  
  CREATE TABLE IF NOT EXISTS recipes (
      recipe_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
      name text,
      ingredients ingredient[],
      // ...
  );
  </code></pre>
  
  <p>Using raw sql, I can insert a row by:</p>
  
  <p><code>INSERT INTO recipes (name, ingredients) VALUES ('some_name', ARRAY[ROW('aa', 'bb', 'cc'), ROW('xx', 'yy', 'zz')]::ingredient[]  );</code></p>
  
  <p>But I'm struggling to do this in go with the <code>pq</code> lib. I've created a <code>pq.Array</code> interface:</p>
  
  <pre><code>type Ingredient struct {
      Name string
      Quantity string
      Unit string
  }
  
  type Ingredients []*Ingredient
  
  func (ings *Ingredients) ConvertValue(v interface{}) (driver.Value, error) {
      return "something", nil
  }
  func (ings *Ingredients) Value() (driver.Value, error) {
      val := `ARRAY[]`
      for i, ing := range ings {
          if i != 0 {
              val += ","
          }
          val += fmt.Printf(`ROW('%v','%v','%v')`, ing.Name, ing.Quantity, ing.Unit)
      }
      val += `::ingredient[]`
      return val, nil
  }
  
  
  // and then trying to insert via:
  stmt := `INSERT INTO recipes (
          name,
          ingredients
      )
      VALUES ($1, $2)
  `
  _, err := db.Exec(stmt,
      "some_name",
      &amp;Ingredients{
          &amp;Ingredient{"flour", "3", "cups"},
      },
  )
  </code></pre>
  
  <p>But pg keeps throwing the error:</p>
  
  <pre><code>  Error insertingpq: malformed array literal: "ARRAY[ROW('flour','3','cups')]::ingredient[]"
  </code></pre>
  
  <p>Am I returning an incorrect <code>driver.Value</code>?</p>