ROW_COUNT()

Overview

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

USAGE

ROW_COUNT()

DETAILS

ROW_COUNT() is an information function that returns the number of rows affected by the preceding statement.

The return value is 0 for a DDL statement, such as CREATE TABLE.

The return value is -1 for a SELECT unless that statements outputs data into a file, in which case it returns the number of rows written.

The return value for an INSERT, UPDATE, or DELETE is the count of rows inserted, updated, or deleted.

The returns value of a REPLACE statement is 2 if it updated a value in an existing row or 1 if it either inserted a new row or made no changes.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

CREATE TABLE row_count_example (
  a INT PRIMARY KEY,
  b INT
);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
|           0 |
+-------------+
INSERT INTO row_count_example VALUES
  (1,1), (2,2), (3,3);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
|           3 |
+-------------+
UPDATE row_count_example SET b = 2
WHERE a = 1;
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
|           1 |
+-------------+
UPDATE row_count_example
SET b = 2
WHERE a = 2;
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
|           1 |
+-------------+
DELETE FROM row_count_example
WHERE a < 3;
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
|           2 |
+-------------+
-- Row is already 3, 3
REPLACE INTO row_count_example VALUES (3, 3);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
|           2 |
+-------------+
REPLACE INTO row_count_example VALUES (3, 1);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
|           2 |
+-------------+
REPLACE INTO row_count_example VALUES (4, 4);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
|           1 |
+-------------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES