I'm getting the following behavior on Rails 3.2.8 under JRuby 22.214.171.124 with activerecord-jdbcpostgresql-adapter 1.2.2 (connecting to a Postgres 9.1.4 database):
> m = Model.first
> m.name = 'Paul \u00f6 J' # note the single quotes
=> "Paul \\u00f6 J"
(1.0ms) UPDATE "models" SET "name" = 'Paul \\u00f6 J', "updated_at" = '2012-10-10 21:06:36.429000' WHERE "users"."id" = 2
=> "Paul \\\\u00f6 J"
This looks like an escaping error either in ActiveRecord or the database adapter. It happens on UPDATE, not on SELECT.
It looks like the cause here is that in Postgres 9.1 the default value for the standard_conforming_strings variable changed from off to on. So the easiest solution is probably for ActiveRecord to initialize a Postgres connection with SET standard_conforming_strings=off.
As a workaround for now, is there any way I can cause Rails to issue that command whenever it opens a database connection?
This looks to me like a problem with activerecord-jdbc-adapter. I sent a pull request to that project to SET standard_conforming_strings=off when initializing a connection:
Closing here, but it seems worthwhile for the Rails team to be aware of this issue. And it'd be nice if there were a hook in a Rails project to issue statements like this upon DB initialization, so people could work around such problems without patching the source somewhere or while waiting for their pull requests to get accepted.