-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Row count #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The result object has a 'rowCount' variable which has the number of rows. |
But how do I get the result object if I am using the evented api? I suppose it's possible to do both kind of callbacks but that sounds sort of weird. My concern is that the result set is huge so I would rather want to stick with the event model. |
What about counting the row events?
|
Want to have an indicator on how far away the loading process is from finishing. So I need to know beforehand how many rows there are. |
I'm not 100% sure but I think there is no way to get this information before. The only way I can think of is a another query before the actual query
|
You can also look at the "reltuples" field of the built-in "pg_class" table for an approximate number of rows. This would probably be fine to show how far away the loading process is from finishing. SELECT reltuples FROM pg_class WHERE relname='your_table'; Reference is http://www.postgresql.org/docs/current/interactive/catalog-pg-class.html. Since postgresql doesn't know itself ahead of time how many rows will be returned, the pg module also won't know unless it buffers the whole result. Use the callback api to buffer results, but stick with the evented api to not buffer results. @booo's suggestion will give you a perfectly accurate count, but it is slower since postgresql has to walk the whole table first. |
You're not going to be able to get a count of rows until your last row is returned. Like @booo said you can do a query before the select to get a count of the results. I'm pretty sure postgresql itself is streaming the results as it grabs them. Anyway...the 'CommandComplete' postgres message contains the number of rows in the SELECT statement. And this message comes in after all 'RowData' messages come in...so there's technically no way I can see to support this at the postgres client level even if we wanted to. |
Thanks for all of comments |
This is not really an issue but more of a question. Is there any way of getting the number of rows returned by a query when using the 'row' event ?
The text was updated successfully, but these errors were encountered: