title: Postgres array handling in Doctrine 2, Symfony 2.2
body: <p>I'm trying to use an integer array data type in a postgres DB, using Doctrine 2 as the ORM. Initially, I was creating the form field as an entity type in Symfony and assumed the entities were the source of this error:</p>
  
  <p><code>request.CRITICAL: Doctrine\DBAL\DBALException: An exception occurred while executing 'INSERT INTO actions (bundle_key, name, type, num_installs, countries, enabled) VALUES (?, ?, ?, ?, ?, ?)' with params ["05e4a7e5", "sfsdfdsfs", "1", "3", "O:43:\"Doctrine\\Common\\Collections\\ArrayCollection\":1:{s:54:\"\u0000Doctrine\\Common\\Collections\\ArrayCollection\u0000_elements\";a:3:{i:0;O:39:\"... truncated for SO question ...Bundle\\Entity\\Country\u0000latitude\";s:5:\"18.25\";s:50:\"\u0000AirInstaller\\AdminBundle\\Entity\\Country\u0000longitude\";s:8:\"-63.1667\";}}}", "true"]:</code></p>
  
  <p><code>SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  array value must start with "{" or dimension information (uncaught exception) at /Users/steveadams/Sites/airinstaller/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 47 [] []</code></p>
  
  <p>Upon looking at the crazy serialization going on, I decided to try storing the countries as their ids by building a choice field, making it so the field wouldn't be interpreted as an entity. This failed as well. I then decided to inspect the documentation where I discovered array support in doctrine is actually just a serialized string of a php array! This doesn't work at all if my column type is actually array in the DB.</p>
  
  <p>So my conundrum is this: Do I create a custom mapping type which stores these countries in the proper format for a postgres integer[]: <code>{2,13,26,43}</code></p>
  
  <p>Or do I ask my database admin to change the column to character and store the serialized arrays Doctrine would like to use? That seems so dirty.</p>
  
  <p>In either case I'm pretty disappointed. I'd like to think I'm doing something wrong since the bottom line here is that Doctrine is not supporting an integer[] out of the box. Is that really the case?</p>
  
  <p>Thanks for any input!</p>