title: Selecting records in Postgres when using ANY and arrays on bytea columns
body: <p>I am having trouble querying on bytea columns using the '=ANY(?)' condition in my Postgres database.
  I define a table with bytea column, inserting a byte[] works ok, but the query does not return any results.</p>
  
  <p>See this snippet:</p>
  
  <pre><code>    private static void selectBytes(String url, String username, String password) throws Exception
  {
      Class.forName("org.postgresql.Driver");
  
      Connection conn = DriverManager.getConnection(url, username, password);
  
      Statement statement = conn.createStatement();
      statement.execute("create table bytetest(x bytea)");
      statement.close();
  
      PreparedStatement ps = conn.prepareStatement("insert into bytetest(x) values(?)");
      ps.setBytes(1, new byte[] { 1, 2, 3, 4 });
      ps.execute();
      ps.close();
  
      statement = conn.createStatement();
      ResultSet rs = statement.executeQuery("select count(*) from bytetest");
      rs.next();
      System.out.println("Number of records: " + rs.getInt(1));
      rs.close();
      statement.close();
  
      ps = conn.prepareStatement("select count(*) from bytetest where x = ANY(?)");
      Array array = conn.createArrayOf("bytea", new Object[] { new byte[] { 1, 2, 3, 4 } });
      ps.setArray(1, array);
      rs = ps.executeQuery();
      rs.next();
      System.out.println("Number of selected records: " + rs.getInt(1));
      rs.close();
      ps.close();
  
      ps = conn.prepareStatement("select count(*) from bytetest where x = ?");
      ps.setBytes(1, new byte[] { 1, 2, 3, 4 });
      rs = ps.executeQuery();
      rs.next();
      System.out.println("Number of selected records directly: " + rs.getInt(1));
      rs.close();
      ps.close();
  
      conn.close();
  }
  </code></pre>
  
  <p>The output is :</p>
  
  <pre><code>Number of records: 1
  Number of selected records: 0
  Number of selected records directly: 1
  </code></pre>
  
  <p>Output from the log shows that the array is not interpreted the same way as the single value.</p>
  
  <pre><code>LOG:  execute &lt;unnamed&gt;: select count(*) from bytetest where x = ANY($1)
  DETAIL:  parameters: $1 = '{{"\\x31","\\x32","\\x33","\\x34"}}'
  LOG:  execute &lt;unnamed&gt;: select count(*) from bytetest where x = $1
  DETAIL:  parameters: $1 = '\x01020304'
  </code></pre>
  
  <p>This is with the PostgreSQL 9.6.3 and the postgresql-42.2.10 driver.
  How can I select my data with ANY and binary data in PostgreSQL?</p>