Bang my head on creating a view from within an ActiveRecord migration for a while:
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "CREATE" LINE 1: CREATE OR REPLACE VIEW searchables AS SELECT entity_id as s...
I wanted to use a file as input. Although the same string directly in the source code would work, the output from IO.read wouldn't. I finally traced this down to the "invisible" BOM being submitted to pg and fixed it by removing it:
filename = File.expand_path('../views/searchables.sql', File.dirname(__FILE__)) # remove UTF-8 BOM execute IO.read(filename).gsub!("\xEF\xBB\xBF".force_encoding("UTF-8"), '')
...could this be done automatically?