MagicStack / MagicStack/asyncpg

Get number of rows in cursor ? (equivalent to psycopg2#cursor.rowcount)

Open
#359 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
8.1k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

  • asyncpg version: 0.15
  • PostgreSQL version: 9.6
  • Python version: 3.6.5
  • Platform: Debian Buster
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: no
  • Can the issue be reproduced under both asyncio and uvloop?: N/A

Warning: It's may be a duplicate of #311

I would like to get the number of rows from the last query (a SELECT query). An equivalent to cursor.rowcount in psycopg2.

I saw in #311 that we can get the query status line (as a string) from execute function. Actually, I'm not able to use it since I need a cursor. Don't know very well binary protocol of pg.. I don't even know if it is possible to get it.

The purpose of this issue is to avoid doing multiple queries (for instance with count(*) statement).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the cursor API and the execute function, then review the PostgreSQL status-line behavior referenced in the issue. Determine whether a cursor can expose the row count from its last SELECT without an additional count(*) query, and add coverage for the requested behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.