Public Instance methods
loose_count(table)
Look at the table statistics for the given table to get an approximate count of the number of rows.
[show source]
# File lib/sequel/extensions/pg_loose_count.rb 35 def loose_count(table) 36 from(:pg_class).where(:oid=>regclass_oid(table)).get(Sequel.cast(:reltuples, Integer)) 37 end
loose_counts(schema)
Look at the table statistics for the given schema and return a hash with table name keys and approximate counts. Results include normal tables, materialized views, and partitioned tables.
[show source]
# File lib/sequel/extensions/pg_loose_count.rb 42 def loose_counts(schema) 43 case schema 44 when Symbol 45 schema = schema.to_s 46 when String 47 nil 48 when SQL::Identifier 49 schema = schema.value.to_s 50 else 51 raise Error, "unsupported argument type, should be symbol, string, or Sequel::SQL::Identifier, given #{schema.inspect}" 52 end 53 54 namespace_oid = if server_version >= 90500 55 Sequel.function(:to_regnamespace, schema).cast(:oid) 56 else 57 from(:pg_namespace).where(nspname: schema).select(:oid) 58 end 59 60 hash = {} 61 from(:pg_class). 62 where(relnamespace: namespace_oid, relkind: %w"r m p"). 63 order(:relname). 64 select_map([:relname, Sequel.cast(:reltuples, Integer).as(:v)]). 65 each do |k, v| 66 hash[k.to_sym] = v 67 end 68 hash 69 end