   CONSTRAINT pk_matching_tables PRIMARY KEY (id_matching_table)
 );
 
-CREATE TABLE matching_fields
-(
-  source_field text NOT NULL,
+id_matching_field serial NOT NULL,
+  source_field text,
+  source_default_value text, -- Valeur par défaut à insérer si la valeur attendue dans le champ de la table de destination n'existe pas dans la table source
   target_field text NOT NULL,
-  target_field_type text NOT NULL,
-  comments text,
+  target_field_type text,
+  field_comments text,
   id_matching_table integer NOT NULL,
-  CONSTRAINT pk_matching_fields PRIMARY KEY (source_field, target_field, id_matching_table)
+  CONSTRAINT pk_matching_fields PRIMARY KEY (id_matching_field)
 );
+COMMENT ON COLUMN gn_imports.matching_fields.source_default_value IS 'Valeur par défaut à insérer si la valeur attendue dans le champ de la table de destination n''existe pas dans la table source';
+
 
 CREATE TABLE matching_geoms
 (

    ADD CONSTRAINT fk_matching_geoms_matching_tables FOREIGN KEY (id_matching_table) REFERENCES matching_tables(id_matching_table) ON UPDATE CASCADE ON DELETE NO ACTION;
ALTER TABLE ONLY matching_fields
    ADD CONSTRAINT fk_matching_fields_matching_tables FOREIGN KEY (id_matching_table) REFERENCES matching_tables(id_matching_table) ON UPDATE CASCADE ON DELETE NO ACTION;


-------------

    col text; -- variable to keep the column name at each iteration
    sname text; --destination schema name
    tname text; --destination table name
BEGIN
    create temp table import (line text) on commit drop;
    --import all csv content
    EXECUTE format('copy import from %L', csv_file);
    -- if not blank, change the csv_temp_table name to the name given as parameter
    IF length(target_table) > 0 THEN
	--split schema.table to 2 strings
