Skip to content

cursor.rowcount with cursor.executemany() regression as of 3.0.6 #178

@zzzeek

Description

@zzzeek

heya -

this started failing as of psycopg 3.0.6. passes with 3.0.5

import psycopg

conn = psycopg.connect(user="scott", password="tiger", dbname="test", host="pg13")
cursor = conn.cursor()

cursor.execute("""
CREATE TABLE parent (
	id SERIAL NOT NULL,
	data INTEGER,
	PRIMARY KEY (id)
)
""")
cursor.executemany("""INSERT INTO parent (id, data) VALUES (%(id)s::INTEGER, %(data)s::INTEGER)""",
    ({'id': 1, 'data': 2}, {'id': 2, 'data': 3})
)
cursor.execute("""DELETE from parent""")

assert cursor.rowcount == 2

cursor.executemany("""DELETE FROM parent WHERE parent.id = %(id)s::INTEGER""", ({'id': 1}, {'id': 2}))
assert cursor.rowcount == 0, f"{cursor.rowcount}"

or more simply

import psycopg

conn = psycopg.connect(user="scott", password="tiger", dbname="test", host="pg13")
cursor = conn.cursor()

cursor.execute("""
CREATE TABLE parent (
	id SERIAL NOT NULL,
	data INTEGER,
	PRIMARY KEY (id)
)
""")

cursor.executemany("""DELETE FROM parent WHERE parent.id = %(id)s::INTEGER""", ({'id': 1}, {'id': 2}))
assert cursor.rowcount == 0, f"{cursor.rowcount}"

also fails.

the cursor.rowcount is -1 when using version 3.0.6, it's 0 for previous versions. it seems to be related executemany() not matching any rows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions