 -- COPY PROJECTS
 \copy (select * from projects where id like 'xxx%') TO '/home/alessia.bardi/migrate-projects/xxx/xxx_projects-beta.sql' CSV;
 -- COPY funding paths
 \copy (select * from fundingpaths where id like 'xxx%') TO '/home/alessia.bardi/migrate-projects/xxx/xxx_fundingpaths-beta.sql' CSV;
 -- COPY project_fundingpath
\copy (select * from project_fundingpath where project like 'xxx%') TO '/home/alessia.bardi/migrate-projects/xxx/xxx_project_fundingpath-beta.sql' CSV;
-- COPY organizations
\copy (select * from dsm_organizations where id like 'xxx%') TO '/home/alessia.bardi/migrate-projects/xxx/xxx_orgs-beta.sql' CSV;
-- COPY participants links (project_organization)
\copy (select * from project_organization where project like 'xxx%') TO '/home/alessia.bardi/migrate-projects/xxx/xxx_project_orgs-beta.sql' CSV;

CREATE TEMP TABLE xxx_projects (
 id varchar(255),
 code varchar(255),
 websiteurl varchar(255),
 acronym varchar(255),
 title text,
 startdate date,
 enddate date,
 call_identifier varchar(255),
 keywords text,
 duration integer,
 ec_sc39 boolean,
 collectedfrom varchar(255),
 contracttypeclass varchar(255),
 contracttypescheme varchar(255),
 inferred boolean,
 deletedbyinference boolean,
 trust double precision,
 inferenceprovenance varchar(255),
 optional1 varchar(255),
 optional2 varchar(255),
 dateofcollection date,
 provenanceactionclass varchar(255),
 provenanceactionscheme varchar(255),
 _dnet_resource_identifier_ varchar(2048),
 oa_mandate_for_publications boolean,
 ec_article29_3 boolean,
 jsonextrainfo text,
 contactfullname text,
 contactfax text,
 contactphone text,
 contactemail text,
 lastupdate date,
 summary text,
 currency text,
 totalcost numeric,
 fundedamount numeric,
 contracttypename varchar(255)
);

-- fill it
 \copy xxx_projects from '/home/alessia.bardi/migrate-projects/xxx/xxx_projects-beta.sql' CSV;

 -- use it to insert into projects

 INSERT INTO projects select * from xxx_projects;

CREATE TEMP TABLE xxx_fundingpaths (
_dnet_resource_identifier_ varchar(2048),
id varchar(512),
 path text,
 funder varchar(512),
 jurisdiction varchar(16),
 description varchar(512),
 optional1 varchar(255),
 optional2 varchar(255),
 funderid varchar(255)
);

-- fill it
 \copy xxx_fundingpaths from '/home/alessia.bardi/migrate-projects/xxx/xxx_fundingpaths-beta.sql' CSV;

 -- use it to insert
 INSERT INTO fundingpaths select * from xxx_fundingpaths;


 CREATE TEMP TABLE xxx_project_fundingpath (
 _dnet_resource_identifier_ varchar(2048),
 funding varchar(255),
 project varchar(255),
 startdate date,
 enddate date,
 semanticclass varchar(255),
 semanticscheme varchar(255),
 optional1 varchar(255),
 optional2 varchar(255)
 );

 -- fill it
 \copy xxx_project_fundingpath from '/home/alessia.bardi/migrate-projects/xxx/xxx_project_fundingpath-beta.sql' CSV;

 -- use it to insert
 INSERT INTO project_fundingpath select * from xxx_project_fundingpath;

 CREATE TEMP TABLE xxx_orgs (
 id varchar(255),
 legalshortname varchar(255),
 legalname varchar(255),
 websiteurl text,
 logourl varchar(255),
 ec_legalbody boolean,
 ec_legalperson boolean,
 ec_nonprofit boolean,
 ec_researchorganization boolean,
 ec_highereducation boolean,
 ec_internationalorganizationeurinterests boolean,
 ec_internationalorganization boolean,
 ec_enterprise boolean,
 ec_smevalidated boolean,
 ec_nutscode boolean,
 country varchar(255),
 collectedfrom varchar(255),
 optional1 varchar(255),
 optional2 varchar(255),
 dateofcollection date,
 provenanceaction varchar(255),
 _dnet_resource_identifier_ varchar(2048),
 lastupdate date,
 trust double precision
 );

 -- fill it
 \copy xxx_orgs from '/home/alessia.bardi/migrate-projects/xxx/xxx_orgs-beta.sql' CSV;

 -- use it to insert
 INSERT INTO dsm_organizations select * from xxx_orgs;

 CREATE TEMP TABLE xxx_project_orgs (
 participantnumber int,
 project varchar(255),
 resporganization varchar(255),
 semanticclass varchar(255),
 trust double precision,
 _dnet_resource_identifier_ varchar(2048),
 contribution numeric,
 currency text
 );

-- fill it
 \copy xxx_project_orgs from '/home/alessia.bardi/migrate-projects/xxx/xxx_project_orgs-beta.sql' CSV;

 -- use it to insert
 INSERT INTO project_organization select * from xxx_project_orgs;