Mysql2::Error: Unknown column 'users.*' in 'field list'

1.4k views Asked by At

I'm seeing this error thrown for multiple tables. Searching StackOverflow it seems most peoples problems are related to a specific column missing but in my case it's trying to select everything ie. using "*".

Anyone have any insight?

Mysql2::Error: Unknown column 'users.*' in 'field list'

UPDATE

From the rails log:

Mysql2::Error: Unknown column 'users.*' in 'field list': SELECT  `users`.`*` FROM `users`  WHERE `users`.`id` = 53  ORDER BY `users`.`id` ASC LIMIT 1

I figured out how to reproduce this locally or at least how I think it may be occurring:

2.1.2 :037 > client = Mysql2::Client.new(:host => "localhost", :username => "root",  :password => "root", :database => "development")
 => #<Mysql2::Client:0x007ff45b72dd30 @read_timeout=nil, @query_options={:as=>:hash, :async=>false, :cast_booleans=>false, :symbolize_keys=>false, :database_timezone=>:local, :application_timezone=>nil, :cache_rows=>true, :connect_flags=>2147525125, :cast=>true, :host=>"localhost", :username=>"root", :password=>"root", :database=>"development"}> 
2.1.2 :038 > result = client.query("SELECT `users`.`*` FROM `users` LIMIT 1")
Mysql2::Error: Unknown column 'users.*' in 'field list'
    from (irb):40:in `query'
    from (irb):40
    from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/console.rb:90:in `start'
    from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/console.rb:9:in `start'
    from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

The query:

SELECT `users`.`*` FROM `users` LIMIT 1

fails when the special all selector * is wrapped in quotes.

SELECT `users`.* FROM `users` LIMIT 1

works without issue. Perhaps that is a MySQL thing? Regardless, these queries are generated by ActiveRecord / ActiveModel so perhaps I've found a bug.

0

There are 0 answers