0

The following query is working in Sequel:

table_sizes = db_config["SELECT table_name,table_rows / 1000000 as table_rows, data_length / 1000000 as data_length, index_length / 1000000 as index_length,round(((data_length + index_length) / 1024 / 1024 / 1024),5) 'size'
FROM information_schema.TABLES 
WHERE table_schema = '#{db_name}' and table_name in ('table1','table2','table3'....'table20')"]

But, when I do something like this, neither of the queries work:

arr = ['table1','table2','table3'...'table20']

table_sizes = db_config["SELECT table_name,table_rows / 1000000 as table_rows, data_length / 1000000 as data_length, index_length / 1000000 as index_length,round(((data_length + index_length) / 1024 / 1024 / 1024),5) 'size'
FROM information_schema.TABLES 
WHERE table_schema = '#{db_name}'"].filter(:table_name => arr)

or:

table_sizes = db_config["SELECT table_name,table_rows / 1000000 as table_rows, data_length / 1000000 as data_length, index_length / 1000000 as index_length,round(((data_length + index_length) / 1024 / 1024 / 1024),5) 'size'
FROM information_schema.TABLES 
WHERE table_schema = '#{db_name}'"].where(:table_name => arr)

What's the best way I should go about this? Does Sequel not support filtering after results?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Pratik Bothra
  • 2,642
  • 2
  • 30
  • 44
  • Rather than try to wrap SQL queries in a Sequel table data set, learn to use Sequel to make the query. What you are doing is almost no improvement over writing raw SQL and doesn't take advantage of Sequel's strengths. – the Tin Man May 27 '13 at 14:47

1 Answers1

1

How is Sequel going to support filtering after getting the results from a query? Its job is done at that point.

Sequel is an ORM and it reduces your need to write SQL queries, hands the query generated to the DBM, retrieves the results and passes them to your code.

Once you receive the results Sequel is out of the picture.

Basically you are using Sequel to provide a connection to the database, and are ignoring all its other strengths and features.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • I usually use the strengths of Sequel...This is the first time I wrapped a query in sequel. It isn't my way, but I had little choice. Thanks anyways – Pratik Bothra May 28 '13 at 09:20