If you make this a JdbcFunction, you may get away with fewer special cases.
http://jdbc.postgresql.org/documentation/head/escaped-functions.html
http://db.apache.org/derby/docs/10.3/ref/rrefjdbc88908.html
http://technet.microsoft.com/en-us/library/ms378045.aspx
http://www.jooq.org/doc/3.0/manual/sql-execution/stored-procedures/#N12886