rails/rails — Issue #3719: PostgresqlAdapter#schema_search_path= does not handle all possible schema names
Author: ldenman
Created: 2011-11-22 15:36:13+00:00
State: open

We have been developing a multi-tenant rails app on 3.0.10 with help from the Apartment gem by Brad Robertson. Currently if one has a schema that starts with a number or has hyphens in it then schema_search_path raises a Postgres error:

ActiveRecord::Base.connection.schema_search_path = "7greenfarm"

throws the following:

PGError: ERROR: syntax error at or near \"greenfarm\"
LINE 1: SET search_path TO 7greenfarm

It seems possible to allow Postgres to use such schemas if they are wrapped in quotes. This seems like a possible fix:

def schema_search_path=(schema_csv)
if schema_csv
execute "SET search_path TO \"#{schema_csv}\""
@schema_search_path = schema_csv
end
end

Is there some reason to not allow such Postgres schema search paths from being set?

We would be willing to write some tests and submit a patch if this seems to be a desirable feature.