Sha256: 9803230d61b7bfeb9452737a96190e950c79c0a067c96c10d15e3f5b38357274

Contents?: true

Size: 916 Bytes

Versions: 18

Compression:

Stored size: 916 Bytes

Contents

# The pg_loose_count extension looks at the table statistics
# in the PostgreSQL system tables to get a fast approximate
# count of the number of rows in a given table:
#
#   DB.loose_count(:table) # => 123456
#
# It can also support schema qualified tables:
#
#   DB.loose_count(:schema__table) # => 123456
#
# How accurate this count is depends on the number of rows
# added/deleted from the table since the last time it was
# analyzed.
# 
# To load the extension into the database:
#
#   DB.extension :pg_loose_count

#
module Sequel
  module Postgres
    module LooseCount
      # Look at the table statistics for the given table to get
      # an approximate count of the number of rows.
      def loose_count(table)
        from(:pg_class).where(:oid=>regclass_oid(table)).get(Sequel.cast(:reltuples, Integer))
      end
    end
  end

  Database.register_extension(:pg_loose_count, Postgres::LooseCount)
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
sequel-4.30.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.29.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.28.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.27.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.26.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.25.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.24.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.23.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.22.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.21.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.20.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.19.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.18.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.17.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.16.0 lib/sequel/extensions/pg_loose_count.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/sequel-4.15.0/lib/sequel/extensions/pg_loose_count.rb
sequel-4.15.0 lib/sequel/extensions/pg_loose_count.rb
sequel-4.14.0 lib/sequel/extensions/pg_loose_count.rb