mysql - Not able to query on "group" in active-record in Rails 3.1.11 -
mysql - Not able to query on "group" in active-record in Rails 3.1.11 -
i have application using ruby on rails 3.1.11, ruby 1.9.2, mysql 5.6.19. 1 of model called "managedfile" , contains column called "group"
i able query e.g.
managedfile.select :name managedfile.select "name" managedfile.select :id managedfile.select :exported, etc managedfile.select('distinct name') managedfile.select('distinct id'), etc not managedfile.select :group not managedfile.select "group" nor managedfile.select('distinct group')
it throw exception
1.9.2-head :067 > managedfile.select('distinct group') managedfile load (0.2ms) select distinct grouping `managed_files` mysql::error: have error in sql syntax; check manual corresponds mysql server version right syntax utilize near 'group `managed_files`' @ line 1: select distinct grouping `managed_files` activerecord::statementinvalid: mysql::error: have error in sql syntax; check manual corresponds mysql server version right syntax utilize near 'group `managed_files`' @ line 1: select distinct grouping `managed_files` /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/connection_adapters/mysql_adapter.rb:906:in `prepare' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/connection_adapters/mysql_adapter.rb:906:in `exec_stmt' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/connection_adapters/mysql_adapter.rb:443:in `block in exec_query' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/connection_adapters/abstract_adapter.rb:245:in `block in log' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activesupport-3.1.11/lib/active_support/notifications/instrumenter.rb:21:in `instrument' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/connection_adapters/abstract_adapter.rb:240:in `log' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/connection_adapters/mysql_adapter.rb:442:in `exec_query' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/connection_adapters/mysql_adapter.rb:976:in `select' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/connection_adapters/abstract/database_statements.rb:20:in `select_all' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/base.rb:470:in `find_by_sql' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/relation.rb:112:in `to_a' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/activerecord-3.1.11/lib/active_record/relation.rb:437:in `inspect' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/railties-3.1.11/lib/rails/commands/console.rb:45:in `start' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/railties-3.1.11/lib/rails/commands/console.rb:8:in `start' /secret_path/.rvm/gems/ruby-1.9.2-head@rails3_1_11/gems/railties-3.1.11/lib/rails/commands.rb:40:in `<top (required)>' script/rails:6:in `require' script/rails:6:in `<main>'1.9.2-head :068 >
the keyword group
reserved in mysql. either rename column (recommended), or utilize backticks (`
) escape it.
managedfile.select("`group`")
mysql ruby-on-rails ruby-on-rails-3 activerecord model
Comments
Post a Comment