我使用Rails 3 + Postgresql进行多租户应用程序 我想得到架构的大小..
on sizes_cotroller.rb
class SizesController < ApplicationController
def index
@tablesize = 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 = 'schema2') As bigint) ) As schema_size})
end
end
但输出显示:
[[“264 kB”]]
如何只取大小的值?
示例
264
任何想法?
答案 0 :(得分:1)
假设格式总是[["### kB"]]
,一种方式(在Ruby中)是做一些字符串操作
[1] pry(main)> [["264 kB"]].to_s.gsub(/\D/, '').to_i
=> 264