matchedRowCount

Syntax

matchedRowCount()

Details

Returns the number of rows affected by the most recent INSERT INTO, DELETE, or UPDATE statement executed in the current session.

If none of these statements have been executed in the current session, matchedRowCount returns 0.

The counting rules depend on the type of statement:

  • UPDATE: The number of matched rows, not the number of rows actually modified.

  • DELETE: The number of matched rows, which is equal to the number of rows actually deleted.

  • INSERT INTO: The number of successfully inserted rows; updated rows are not counted.

Parameters

None

Returns

An integer scalar representing the number of affected rows.

Examples

t=table(`XOM`GS`FB as ticker, 100 80 120 as volume);
INSERT INTO t values(`AMZN`GS, 300 100);
matchedRowCount()
// output: 2

UPDATE t set volume=100 where ticker=`GS
matchedRowCount()
// output: 2

sym=`A`B`C`D`E
id=5 5 3 2 1
val=52 64 25 48 71
t=keyedTable(`sym,sym,id,val)

INSERT INTO t values(`A`K, 6 3, 20 62)
matchedRowCount()  
// output: 1


t = table(1..100 as id, rand(100, 100) as value)  
DELETE from t where id < 50  

matchedRowCount()
// output: 49

dbName="dfs://matchedRowCount"
if(existsDatabase(dbName)){
	dropDatabase(dbName)	
}
db = database(dbName, VALUE, 1..10)
t = table(1..10 as id, 1..10 as value)
pt = db.createPartitionedTable(t, `pt, `id)

INSERT INTO t VALUES(11 12 13, 20 30 40)

matchedRowCount() 
// output: 3