GeekToL
GeekToL

Reputation: 1815

Get Size Of Schema Using ActiveRecord

i try get size of schema from name of subdomain.. name of subdomain in schema public,

on controller.rb

@account = Account.find_by_subdomain(params[:subdomain])
@itemlist = Account.find(:all,:select => 'subdomain')
@schemasize = ActiveRecord::Base.connection.select_rows(%q{select pg_size_pretty(CAST((SELECT SUM(pg_total_relation_size(table_schema || '.' || table_name) ) FROM information_schema.tables WHERE table_schema = '}[email protected]_s+%q{') As bigint) )  As schema_size}).to_s.gsub(/\D/, '').to_i

get localhost:3000/namesubdomain

output on command prompt

 (21.0ms)  select pg_size_pretty(CAST((SELECT SUM(pg_total_relation_size(table
_schema || '.' || table_name) ) FROM information_schema.tables WHERE table_schem
a = '[#<Account subdomain: "namesubdomain">]') As bigint) ) As schema_size

i want output on command prompt such as

   (151.0ms)  select pg_size_pretty(CAST((SELECT SUM(pg_total_relation_size(tabl
e_schema || '.' || table_name) ) FROM information_schema.tables WHERE table_sche
ma = 'namesubdomain') As bigint) ) As schema_size

any idea?

Upvotes: 1

Views: 124

Answers (1)

PinnyM
PinnyM

Reputation: 35533

@itemlist.to_s will render the object as a String. Since the object is actually an Array rendering as a string will just output information about the Array instead of the contents. What you probably want is either:

@itemlist.first.subdomain

or:

@itemlist.map(&:subdomain).join(" ")

Upvotes: 1

Related Questions