title: Scala Anorm Postgresql Error When Storing Byte Array
body: <p>I have a database table in Scala Playframework defined as</p>
  
  <pre><code>CREATE TABLE account (
      id     SERIAL,
      email  TEXT  NOT NULL,
      buffer BYTEA NOT NULL,
      PRIMARY KEY (id)
  );
  </code></pre>
  
  <p>I am using a protocol buffer to serialize an object to a byte array with the following code</p>
  
  <pre><code>DB.withConnection{ implicit c=&gt;
    SQL("INSERT INTO device (buffer,secret) VALUES ({secret},{buffer})").on(
      "secret"-&gt;device.getSecret(),
      "buffer"-&gt;device.toByteArray()
    ).executeInsert()
  }
  </code></pre>
  
  <p>The type returned by <code>device.toByteArray()</code> is <code>Array[Byte]</code> which <em>should</em> match the database type for that column. However upon executing the code I get </p>
  
  <pre><code>play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[PSQLException: ERROR: column "buffer" is of type bytea but expression is of type character varying
    Hint: You will need to rewrite or cast the expression.
    Position: 44]]
      at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.3]
      at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.3]
      at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
      at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.3]
      at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2]
      at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2]
  Caused by: org.postgresql.util.PSQLException: ERROR: column "buffer" is of type bytea but expression is of type character varying
  </code></pre>