1

I have following:

recs = conn.execute sql

output:

[{"mk1"=>"test007", 0=>"test007"}, {"mk1"=>"test009", 0=>"test009"}, {"mk1"=>"test0010", 0=>"test0010"}, {"mk1"=>"test00112", 0=>"test00112"}, {"mk1"=>"test345", 0=>"test345"}, {"mk1"=>"testprüfer", 0=>"testprüfer"}, {"mk1"=>"test3455", 0=>"test3455"}, {"mk1"=>"aaaa", 0=>"aaaa"}, {"mk1"=>"pat1", 0=>"pat1"}, {"mk1"=>"pat222", 0=>"pat222"}, {"mk1"=>"poook_patient", 0=>"poook_patient"}, {"mk1"=>"sylviaparient", 0=>"sylviaparient"}, {"mk1"=>"patient_of_sylvia", 0=>"patient_of_sylvia"}, {"mk1"=>"test0005", 0=>"test0005"}, {"mk1"=>"test0006", 0=>"test0006"}]

Is there a fast way to get only the values of "mk1"'s by using maybe not "execute" but something else? I would like to be faster then this one if it is possible:

mk1s = []
recs.each{|l| mks1s.push(l["mk1"]) }

Thank you in advance.

1
  • you'll always retrieve hashes from the database, if you want something better than your code, use .map Commented Jan 19, 2015 at 11:31

1 Answer 1

1

The select_values method does this.

connection.select_values 'select mk1 from ...'

would return an array of those values. If your select statement results in multiple columns, it would ignore columns other than the first one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.