FOUND belongs to the family of special status variables automatically maintained by the PL/pgSQL interpreter. Immediately after every SQL command that can return, move, or affect rows (SELECT INTO, INSERT, UPDATE, DELETE, FETCH, MOVE, FOR loops), PL/pgSQL sets FOUND to:• TRUE – at least one row was returned, moved, or affected.• FALSE – no rows were touched.The variable is INITIALLY NULL when a block starts and is overwritten by each qualifying command, so it must be inspected right after the statement of interest.FOUND is session-local to the executing PL/pgSQL function, anonymous DO block, or procedure. It can be reassigned manually but doing so is rare and can obscure intent. It is not visible in plain SQL, nor in other procedural languages like PL/pgSQL’s cousins (plpythonu, plv8). Outside PostgreSQL, other dialects expose similar concepts under different names (SQL%ROWCOUNT, @@ROWCOUNT, FOUND_ROWS()).
GET DIAGNOSTICS, SQL%ROWCOUNT (Oracle), @@ROWCOUNT (SQL Server), FOUND_ROWS(), ROW_COUNT(), NOT FOUND handling
PostgreSQL 7.0
No. FOUND is just a predefined PL/pgSQL variable and can still be used as an identifier in plain SQL objects.
Yes, you can assign TRUE or FALSE to FOUND, but doing so is unusual and may confuse readers because the interpreter will overwrite it after the next SQL statement.
No. Only commands that inherently deal with row counts (SELECT INTO, INSERT, UPDATE, DELETE, FETCH, MOVE, FOR) update FOUND.
FOUND is a simple boolean flag. GET DIAGNOSTICS ROW_COUNT returns the exact number of rows affected, giving you more granular information when you need the count rather than a boolean.