1

Mysql by default prints table results in mysql table formatting

+----+----------+-------------+
| id | name     | is_override |
+----+----------+-------------+
|  1 | Combined |           0 |
|  2 | Standard |           0 |
+----+----------+-------------+

When calling mysql from the unix shell this table formatting is not preserved, but it's easy to request it via the -t option

mysql -t my_schema < my_query_file.sql

When using Ruby, I'm using the mysql gem to return results. Since the gem returns data as hashes, there's no option to preserve table formatting. However, is there any way I can easily print a hash/data with that formatting? Without having to calculate spacing and such?

db = Mysql.new(my_database, my_username, my_password, my_schema)
result = db.query("select * from my_table")
result.each_hash { |h|
   # Print row. Any way to print it with formatting here?
   puts h 
}
0

1 Answer 1

2

Some gems and codes:

I have not tried any of them.

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

1 Comment

The 2nd option (text-table) is exactly what I was looking for. Thanks!

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.