title: Querying Postgres composite types from golang
body: <p>So I am using go-gorp to query postgres and I can't seem to query the composite type inside my table is giving an error. All I want is appropriately nested JSON response. My postgres schema is:</p>
  
  <pre><code>CREATE TYPE PhoneType AS ENUM ('MOBILE', 'HOME', 'WORK');
  
  CREATE TYPE PhoneNumber AS (
    "Number" VARCHAR,
    "Type" PhoneType
  );
  
  CREATE TABLE Person (
    "Id" SERIAL PRIMARY KEY NOT NULL,
    "Name" VARCHAR NOT NULL,
    "Email" VARCHAR,
    "Number" PhoneNumber[]
  );
  </code></pre>
  
  <p>Correspondingly in golang, I have</p>
  
  <pre><code>const (
    MOBILE PhoneType = iota
    HOME
    WORK
  )
  
  type PhoneNumber struct {
    Number string
    Type   PhoneType
  }
  
  type Person struct {
    Id          int
    Name        string
    Email       string
    PhoneNumber        // not sure how to get array of phone numbers here
  }
  </code></pre>
  
  <p>And to query, I am using go-gorp as follows:</p>
  
  <pre><code>dbmap := &amp;gorp.DbMap{Db: db, Dialect: gorp.PostgresDialect{}}
  var data []Person
  _, err := dbmap.Select(&amp;data, "SELECT * FROM Person")
  </code></pre>
  
  <p>the result I get has the format</p>
  
  <pre><code>{
    "Id":
    "Name":
    "Email"
    "Number": "{\"(..., ...)\"}"
    "Type": 0
  }
  </code></pre>
  
  <p>what I'm expecting is:</p>
  
  <pre><code>{
    "Id":
    "Name":
    "Email":
    "PhoneNumber": [{
      "Number":
      "Type":
    }]
  }
  </code></pre>
  
  <p>How can I change this nested composite type to the type friendly to my declaration in go?</p>
  
  <p>EDIT: Looks like postres arrays and composite types become strings in go. How can I redesign the schema to achieve similar result?</p>