INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'articles', article_id
		FROM eco.p_mouvements_articles
		WHERE article_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'articles')
		GROUP BY 1,2;



INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'categories_articles', categorie_id
		FROM eco.p_mouvements_articles JOIN eco.t_articles ON article_id = t_articles.oid
		WHERE categorie_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'categories_articles')
		GROUP BY 1,2;



INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'sous_categories_articles', sous_categorie_id
		FROM eco.p_mouvements_articles JOIN eco.t_articles ON article_id = t_articles.oid
		WHERE sous_categorie_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'sous_categories_articles')
		GROUP BY 1,2;


INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'familles_articles', famille_id
		FROM eco.p_mouvements_articles JOIN eco.t_articles ON article_id = t_articles.oid
		WHERE famille_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'familles_articles')
		GROUP BY 1,2;



INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'sous_familles_articles', sous_famille_id
		FROM eco.p_mouvements_articles JOIN eco.t_articles ON article_id = t_articles.oid
		WHERE sous_famille_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'sous_familles_articles')
		GROUP BY 1,2;





INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'types_articles', t_articles.type_id
		FROM eco.p_mouvements_articles JOIN eco.t_articles ON article_id = t_articles.oid
		WHERE t_articles.type_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'types_articles')
		GROUP BY 1,2;



INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'unites_stockage_articles', t_articles.unite_stockage_id
		FROM eco.p_mouvements_articles JOIN eco.t_articles ON article_id = t_articles.oid
		WHERE t_articles.unite_stockage_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'unites_stockage_articles')
		GROUP BY 1,2;



INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'gestionnaires', gestionnaire_id
		FROM eco.p_mouvements_articles
		WHERE gestionnaire_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'gestionnaires')
		GROUP BY 1,2;





INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'centres_responsabilites', centre_responsabilite_id
		FROM eco.t_profils_comptables
		WHERE centre_responsabilite_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'centres_responsabilites')
		GROUP BY 1,2;



INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'unites_fonctionnelles', unite_fonctionnelle_id
		FROM eco.t_profils_comptables
		WHERE unite_fonctionnelle_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'unites_fonctionnelles')
		GROUP BY 1,2;




INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'fournisseurs', fournisseur_id
		FROM eco.p_mouvements_articles
		WHERE fournisseur_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'fournisseurs')
		GROUP BY 1,2;


INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'types_fournisseurs', t_fournisseurs.type_id
		FROM eco.p_mouvements_articles JOIN eco.t_fournisseurs ON fournisseur_id = t_fournisseurs.oid
		WHERE t_fournisseurs.type_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'types_fournisseurs')
		GROUP BY 1,2;


INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'lieux_mouvements', lieu_id
		FROM eco.p_mouvements_articles
		WHERE lieu_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'lieux_mouvements')
		GROUP BY 1,2;

INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'lieux_commandes', lieu_livraison_id
		FROM eco.p_commandes
		WHERE lieu_livraison_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'lieux_commandes')
		GROUP BY 1,2;


INSERT INTO eco.p_oids (code_table, oid) 
		SELECT 'types_mouvements', type_mouvement_id
		FROM eco.p_mouvements_articles
		WHERE type_mouvement_id NOT IN (SELECT oid FROM eco.p_oids WHERE code_table = 'types_mouvements')
		GROUP BY 1,2;





