Sha256: 4f52f58361fae246cf21b7b8e1092b648d300408ccf389e5f9650fa8d7b6103c

Contents?: true

Size: 1006 Bytes

Versions: 77

Compression:

Stored size: 1006 Bytes

Contents

# frozen-string-literal: true
#
# 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(Sequel[: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
#
# Related module: Sequel::Postgres::LooseCount

#
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

77 entries across 62 versions & 2 rubygems

Version Path
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.41.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/sequel-5.41.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.39.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.43.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/sequel-5.44.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/sequel-5.38.0/lib/sequel/extensions/pg_loose_count.rb
sequel-5.44.0 lib/sequel/extensions/pg_loose_count.rb
sequel-5.43.0 lib/sequel/extensions/pg_loose_count.rb
sequel-5.42.0 lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/sequel-5.41.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/sequel-5.41.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/sequel-5.38.0/lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/sequel-5.39.0/lib/sequel/extensions/pg_loose_count.rb
sequel-5.41.0 lib/sequel/extensions/pg_loose_count.rb
sequel-5.40.0 lib/sequel/extensions/pg_loose_count.rb
sequel-5.39.0 lib/sequel/extensions/pg_loose_count.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/sequel-5.38.0/lib/sequel/extensions/pg_loose_count.rb