문제

I'm querying a table which has about 15 columns. I only need 13 of those columns. To make the query faster, is there a way to select all but those 2 columns I do not need? Something like:

My_table.select_all_but([:column_5, :column_8]).all
도움이 되었습니까?

해결책

You can do this:

My_table.select ( My_table.column_names - ['column_5', 'column_8'] )

다른 팁

Use pluck

    Person.pluck(:id, :name)
    # SELECT people.id, people.name FROM people
    # => [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top