ROW_COUNT

Returns the number of rows inserted, updated, or deleted by the preceding statement.

Syntax

ROW_COUNT()

Arguments

  • None.

Return Type

int

Examples

The following shows how to use ROW_COUNT() in a query after running an INSERT:

DROP TABLE IF EXISTS account;
CREATE TABLE account(id int, amount decimal(10,2));
INSERT account VALUES(1, 10.00), (2, 30.00);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
|           2 |
+-------------+

This example shows how an application can raise an error if a ROW_COUNT() result is different than expected after a DELETE:

DELIMITER //
CREATE OR REPLACE PROCEDURE delete_account(_id int) RETURNS int AS
DECLARE _row_count int = -1;
BEGIN
DELETE FROM account WHERE account.id = _id;
_row_count = row_count();
IF _row_count = 0 THEN
RAISE user_exception(CONCAT("No rows deleted for account ", _id));
END IF;
RETURN _row_count;
END //
DELIMITER ;

Example use:

ECHO delete_account(3);
ERROR 2242 (HY000): Unhandled exception
Type: ER_USER_RAISE
Message: No rows deleted for account 3
Callstack:
#0 Line 7 in `db1`.`delete_account`
ECHO delete_account(1);
+--------+
| RESULT |
+--------+
| 1 |
+--------+

Last modified: February 24, 2023

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK