Rohita Khatiwada
Rohita Khatiwada

Reputation: 2935

counting rows returned in postgresql

I need to count the number of rows returned from database.By using following code

rv = plpy.execute("SELECT * FROM AA where name = 'active '") 
rv[0]["id"] 

works when some values are returned but I need to check if no values are returned: Can someone help please.

Upvotes: 2

Views: 4996

Answers (4)

Peter Eisentraut
Peter Eisentraut

Reputation: 36749

In PL/Python, the way to get the result size is

rv.nrows

See the documentation.

Upvotes: 3

Milen A. Radev
Milen A. Radev

Reputation: 62633

.rowcount

Upvotes: -1

jishi
jishi

Reputation: 24634

Why don't you just check the size of the rv array?

Upvotes: 4

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55499

Why dont you use -

SELECT Count(*) as rowCount FROM AA where name = 'active'

This will return you the number of rows from the query. If there are no rows, then it will return 0.

Upvotes: 3

Related Questions