0

I'd like to add an extra column to an Arel select result, where the value in the column is the same on every row, so that I can add extra information about the context of the query to a Rails ActiveRecord object.

So, how would I generate this SQL using Arel?

select date('2013-12-25') as foo

It should result in a result with a single column and a single row which contains a date value. I've used MySQL syntax here, but I'd like it to generate correct SQL for whichever backend is being used.

Douglas
  • 36,802
  • 9
  • 76
  • 89

1 Answers1

1

Looks like the answer is:

include Arel
select = SelectManager.new(Table.engine)
select.project(Nodes::NamedFunction.new('date', ['2013-12-25']).as('foo'))
select.to_sql
Douglas
  • 36,802
  • 9
  • 76
  • 89