PostgreSQL 9.3中的@@ ROWCOUNT [英] @@ROWCOUNT in PostgreSQL 9.3

查看:640
本文介绍了PostgreSQL 9.3中的@@ ROWCOUNT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想返回受最后一条语句影响的行数。

I want to returns the number of rows affected by the last statement.

使用Microsoft SQL Server 2008 R2,我这样做是这样的:

Using Microsoft SQL Server 2008 R2 I do it this way:

SELECT * FROM Test_table;

SELECT @@ROWCOUNT AS [Number Of Rows Affected];

将给出:

Number Of Rows Affected
-----------------------
10

在PostgreSQL 9.3中如何?

How about in PostgreSQL 9.3?

推荐答案

AFAIK在postgresql中没有这样的构造,但是行数是从postgresql中获得的结果的一部分。

AFAIK there is no such construct in postgresql however the number of rows is part of the result you get from postgresql.

更正: a_horse_with_no_name在他的注释中指出,在PL / pgSQL中可以使用类似的东西。另请参见
Achilles Ram Nakirekanti发布的答案中的示例

CORRECTION: as a_horse_with_no_name states in his comment there is something similar which can be used within PL/pgSQL. Also see example in answer posted by Achilles Ram Nakirekanti

从程序内部,但是我最初的建议在大多数情况下比较容易,然后不得不诉诸PL的使用/ pgSQL。

From within programs however my original suggestion is in most cases easier then having to resort to the usage of PL/pgSQL.

使用libpq时:
在选择结果上,可以使用PQntuples确定返回的行数。对于更新,插入和删除,您可以使用PQcmdTuples并获得结果以影响受影响的行数。

When using libpq: On the result of a select you can use PQntuples to determine the number of rows returned. For update, insert and delete you can use PQcmdTuples with the result to get the number of rows affected.

其他客户端库通常具有类似的功能。

Other client libraries often have similar functionality.

这篇关于PostgreSQL 9.3中的@@ ROWCOUNT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆