Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 487
Rohita Khatiwada Avatar asked Apr 21 '26 10:04

Rohita Khatiwada


2 Answers

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

like image 103
jishi Avatar answered Apr 24 '26 00:04

jishi


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.

like image 26
Sachin Shanbhag Avatar answered Apr 24 '26 00:04

Sachin Shanbhag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!