﻿CREATE OR REPLACE FUNCTION file_controleur (id_marche integer) RETURNS text AS $$

DECLARE

	resultat text;

BEGIN

	CREATE TEMP TABLE controleur_aramis AS
	SELECT c.id_controleur, c.modele, c.id_unite_maintenance
	FROM controleur c
	INNER JOIN unite_maintenance um on um.id_unite_maintenance=c.id_unite_maintenance
	INNER JOIN contrats ctr on ctr.id_contrats = um.id_contrats
	Where ctr.id_contrats = id_marche;

	COPY controleur_aramis
	TO 'g:/ARAMIS/controleur.txt' DELIMITER ';' ;

DROP  TABLE controleur_aramis;
RETURN resultat;

END;
$$ LANGUAGE plpgsql;


--SELECT * FROM file_controleur (5);
