ActiveRecord doubles backslashes in string and text columns #7903

pjungwir opened this Issue Oct 10, 2012 · 2 comments

1 participant


I'm getting the following behavior on Rails 3.2.8 under JRuby with activerecord-jdbcpostgresql-adapter 1.2.2 (connecting to a Postgres 9.1.4 database):

> m = Model.first
> = '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
> m.reload
 => "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.

@pjungwir pjungwir closed this Oct 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment