Thread: Table count option
<br /><p><font face="Arial">Right clicking on a table show the "count" option, which updates the Rows(counted) value in theproperties window for the table.</font><p><font face="Arial">Is there an equivalent SQL command? ANALYZE<i> table_name</i> does not work as the equivalent.</font>
Melvin Davidson wrote: > > Right clicking on a table show the "count" option, which updates the > Rows(counted) value in the properties window for the table. > > Is there an equivalent SQL command? ANALYZE/ table_name/ does not work > as the equivalent. > SELECT count(*) FROM table; Regards Dave
Melvin Davidson wrote: > Dave, > > Yes SELECT count(*) FROM table; will give me a count of rows > but it does _not_ update the "Rows(counted) value in the properties > window" > > So what is the equivalent function to update the "Rows(counted) value in > the properties window"??? Right-click -> Count. The value shown is retrieved on the fly using SELECT count(*), but only if the estimated value is lower than the threshold set under Tools->Options (unless you explicitly select Count from the menu). Regards, Dave
Melvin Davidson wrote: > OK, one more time. > > Yes I know that right click count does that! > > I know about select count(*). > I know about Right-click -> Count > > The question was/is "What is the equivalent SQL function to update the > Rows(counted) value? Right, one more time :-) There is no SQL function. It just does a SELECT count(*) and updates the value stored in memory (in the pgTable object to be precise). > IOW, What is the underlying code in Right-click -> Count? Ultimately, once you get clear of all the menu handling code you get to: void pgTable::UpdateRows() { pgSet *props = ExecuteSet(wxT("SELECT count(*) AS rows FROM ONLY ") + GetQuotedFullIdentifier()); if (props) { rows = props->GetLongLong(0); delete props; rowsCounted= true; } } pgTable.rows contains the row count. pgTable.rowsCounted is a flag that indicates that a count has been done, rather than an estimate made (estimates come from pg_class.reltuples, which is populated by ANALYZE). Regards, Dave