开发者

counting rows returned in postgresql

开发者 https://www.devze.com 2023-02-14 02:48 出处:网络
I need to count the n开发者_JS百科umber of rows returned from database.Byusing following code rv = plpy.execute(\"SELECT * FROM AA where name = \'active \'\")

I need to count the n开发者_JS百科umber 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.


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


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.


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

rv.nrows

See the documentation.


.rowcount

0

精彩评论

暂无评论...
验证码 换一张
取 消