update A set x = '0' where [condition];
if the where clause is not met, the update fails.
depending on this, I want to call an insert into another table, but only if the update was performed - that is, ROW_COUNT ()> 0.
How can I do this with a single request?
I tried this:
update A set x = '0' where [condition]; if row_count() > 0 then insert into [...]; end if;
this leads to an error.
PS:
The question is exclusively about the ability to perform the update and conditional insertion into one db request. SQL-Injection-safty is provided using prepared statements.
source share