Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:07:54+00:00 2026-06-13T04:07:54+00:00

I have a query in my ruby file : @mastertest = connection.execute(select code_ver,date from

  • 0

I have a query in my ruby file :

@mastertest = connection.execute("select code_ver,date from mastertest")

And I print the result of the query as below:

@mastertest.each do |row|
  puts row[0] : row[1]
end

This will print all the code_ver and ‘date’ which looks like this

2.0 : 2012/12/10
3.1 : 2012/11/03
2.5 : 2012/07/08
1.8 : 2012/12/11
2.5 : 2012/03/01

Now I want to sort this array based on my code_ver, but the problem is ruby does not consider this as an array, it says it is some mysql2 type.

How do I proceed further? I want to either convert this thing to 2-d array or I would want to sort it based on the row[0].

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:07:55+00:00Added an answer on June 13, 2026 at 4:07 am

    You’re getting a MySQL result set object in @mastertest and a result set is not an array.

    If you’re using mysql2, then you should have a Mysql2::Result and that’s Enumerable so it has a to_a method:

    @mastertest.to_a.sort { ... }
    

    If you’re using the mysql gem, then you should have a Mysql::Result and you’ll have to convert @mastertest to an Array by hand:

    a = [ ]
    @mastertest.each { |r| a.push(...) }
    a.sort { ... }
    

    Or you could simply let the database do the sorting:

    @mastertest = connection.execute('select code_ver, date from mastertest order by code_ver')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query in my Ruby file: @mastertest = connection.execute(select code_ver, date from
I have code to run sql query in ruby as follows sql = ActiveRecord::Base.connection()
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
We have MySQL slow query logs from a suite of applications, mostly in Ruby,
I have the following query: SELECT COUNT(employees.id) AS emp_count FROM `orders` INNER JOIN `companies`
I have small ruby function to return a query result. I want to check
I have a query that successfully grabs the unique products from my products table
I have a question about doing a query through a few associations using Ruby
We have a ruby based API that our C# service needs to query that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.