title: Escaping formula for Grails derived properties
body: <p>Grails offers <a href="http://grails.org/doc/latest/guide/GORM.html#5.5.2.11%20Derived%20Properties" rel="nofollow">derived properties</a> to generate a field from a SQL expression using the <em>formula</em> mapping parameter:</p>
  
  <pre><code>static mapping = {
      myfield formula: "field1 + field2"
  }
  </code></pre>
  
  <p>I'm trying to use the formula parameter with a PostgreSQL database to make a concatenated field. The syntax is a little strange since PostgreSQL 8.4 doesn't yet support concat_ws:</p>
  
  <pre><code>static mapping = {
      myfield formula: "array_to_string(array[field1, field2],' ')"
  }
  </code></pre>
  
  <p>The produced SQL shown with <em>loggingSql = true</em> in the DataSource config has the table prefix inserted into some strange places:</p>
  
  <pre><code>select table0_.field1 as field1_19_0_,
         table0_.field2 as field2_19_0_,=
         array_to_string(table0_.array[field1, table0_.field2], ' ') as formula0_0_
  from test_table table0_ where table0_.id=?
  </code></pre>
  
  <p>The table prefix errantly appears before <em>array</em> but not before <em>field1</em> in the derived formula. Is there a way to escape the prefix or correct this behavior more explicitly?</p>