Sample Header Ad - 728x90

Stuck at inserting records into MariaDB conditionally

0 votes
1 answer
272 views
I know about insert ignore. That's of no use, because MariaDB does not consider NULL to be part of the uniqude index. Therefore I have to use if ... else. But this code does not run:
select *
from Nodes 
where Key = 'FAQPage';

if not found_row() then
   insert into Nodes (Key, ParentId)
   values ('FAQPage', null)
end if;
How can I use if ... else to conditionally insert data in MariaDB?
Asked by Saeed Neamati (1515 rep)
Feb 5, 2022, 10:23 AM
Last activity: Feb 5, 2022, 04:57 PM