Class: ActiveRecord::Timescale::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/active_record/timescale/base.rb

Class Method Summary collapse

Class Method Details

.approximate_row_countObject

Get approximate row count for hypertable, distributed hypertable, or regular PostgreSQL table based on catalog estimates. This function supports tables with nested inheritance and declarative partitioning.

The accuracy of approximate_row_count depends on the database having up-to-date statistics about the table or hypertable, which are updated by VACUUM, ANALYZE, and a few DDL commands. If you have auto-vacuum configured on your table or hypertable, or changes to the table are relatively infrequent, you might not need to explicitly ANALYZE your table as shown below. Otherwise, if your table statistics are too out-of-date, running this command updates your statistics and yields more accurate approximation results.



38
39
40
# File 'lib/active_record/timescale/base.rb', line 38

def approximate_row_count
  execute sanitize_sql(["SELECT * FROM approximate_row_count(?)", quote_table_name(table_name)])
end