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

DECLARE

	resultat varchar(1000);

BEGIN

	CREATE TEMP TABLE support_aramis AS

	SELECT um.id_unite_maintenance, id_supports, code_support, type_support, sup.etat, hauteur, id_detail_support
	FROM supports sup
	INNER JOIN unite_maintenance um on um.id_unite_maintenance=sup.id_unite_maintenance
	INNER JOIN contrats ctr on ctr.id_contrats = um.id_contrats
	INNER JOIN detail_support dsup ON sup.id_supports = dsup.id_support
	Where ctr.id_contrats = id_marche;
	

	COPY support_aramis
	TO 'g:/ARAMIS/support.txt' DELIMITER ';' ;

DROP  TABLE support_aramis;
RETURN resultat;

END;
$$ LANGUAGE plpgsql;

--SELECT * FROM file_support (5)




