I'm currently learning how to use databases through PostgreSQL. I'm defining a function that will add rows from one table to another based on various conditions, one condition is that if the row already exists in the target table, it won't be added but no exception will be raised, the program will simply continue onto the next row. As you may have guessed all of this is taking place within LOOP...END LOOP; of a FOR.
The problem is that our professor considers ON CONFLICT DO NOTHING non-standard and insists we use another method. I have searched extensively but really don't understand how to apply some answers people have suggested in similar cases. My idea was indeed:
IF variable1, variable2, variable3 NOT IN (SELECT v1, v2, v3 FROM target_table) THEN INSERT INTO target_table VALUES(variable1, variable2, variable3); END IF;
But that is obviously not correct from a syntax point of view. Can anybody give me some guidance?
Thanks
Aucun commentaire:
Enregistrer un commentaire