This is a read-only copy of the MariaDB Knowledgebase generated on 2024-11-15. For the latest, interactive version please visit https://mariadb.com/kb/.

Trying to insert if not exist in a recursive statement

Hi MariaDB users,

I'm from Chile and i need to make a question.

I'm trying to make an insert if not exist or an insert on duplicate key update. i'm using 10.3.16 Version allocating a Bitnami Testlink DB.

well, my problem is:

i'm making a insert using a recursive statement into a not temporal table, so i need to run this query a few times in a day but when re run i've got a duplicate error on primary key.

How can i make an insert with these recursive query?.

so my query is like this

  1. Inserto los datos que genera la consulta recursividad. INSERT id_casos(id, name) WITH RECURSIVE CTE_TESTLINK (Id, parent_id, name, node_type_id) AS( SELECT Id, parent_id, 'Beneficios Adicionales', node_type_id FROM nodes_hierarchy WHERE name = 'Beneficios Adicionales' UNION ALL SELECT nh.Id, nh.parent_id, 'Beneficios Adicionales', nh.node_type_id FROM nodes_hierarchy nh INNER JOIN CTE_TESTLINK cte ON nh.parent_id = cte.Id ) SELECT id, name FROM CTE_TESTLINK WHERE node_type_id = X

thanks in advance!!

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.