Search code examples
sqlrubysqlitesequel

In SQL, how can I select a modified column?


I am trying to do this using SQL in Ruby:

SELECT number*2 FROM dictionary;

I can use .select(:number) to get the number columns "as is", but I have no idea how to return them modified. I tried this (which obviously didn't work):

current_table.select(:number*2)

Solution

  • Try either of these

    @newnumber = number.find(:all, :conditions => ["id = ?", @dictionary.id], :select => "number * 2 as newnumber")
    
    @newnumber = number.all(:conditions=>"id='#{@dictionary.id}'",:select=>"number * 2 as newnumber")