SQL Server → PostgreSQL

@@ROWCOUNT Equivalent in PostgreSQL: Checking Rows Affected

Replace @@ROWCOUNT in T-SQL procedures with FOUND or GET DIAGNOSTICS in PL/pgSQL during PostgreSQL migration.

@@ROWCOUNT is a SQL Server global that reflects how many rows the last command affected. In PostgreSQL, inside PL/pgSQL, use the special FOUND variable or GET DIAGNOSTICS.

FOUND after UPDATE/DELETE

SQL Server

UPDATE products SET active = 0 WHERE id = 10;
IF @@ROWCOUNT = 0
  THROW 50001, 'No rows', 1;

PostgreSQL

UPDATE products SET active = false WHERE id = 10;
IF NOT FOUND THEN
  RAISE EXCEPTION 'No rows';
END IF;

Analisador de Impacto

Convert entire procedures with automatic @@ROWCOUNT replacement — test in the converter or run batch diagnostics.

Abrir Análise de Projeto →