Method: Sequel::Dataset#select_map

Defined in:
lib/sequel/dataset/actions.rb

#select_map(column = nil, &block) ⇒ Object

Selects the column given (either as an argument or as a block), and returns an array of all values of that column in the dataset.

DB[:table].select_map(:id) # SELECT id FROM table
# => [3, 5, 8, 1, ...]

DB[:table].select_map{id * 2} # SELECT (id * 2) FROM table
# => [6, 10, 16, 2, ...]

You can also provide an array of column names:

DB[:table].select_map([:id, :name]) # SELECT id, name FROM table
# => [[1, 'A'], [2, 'B'], [3, 'C'], ...]

If you provide an array of expressions, you must be sure that each entry in the array has an alias that Sequel can determine.



775
776
777
# File 'lib/sequel/dataset/actions.rb', line 775

def select_map(column=nil, &block)
  _select_map(column, false, &block)
end