Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create or replace function carica_item(_file_path text)
- returns void as
- $body$
- begin
- drop table if exists itemdata;
- CREATE temp TABLE itemdata
- (
- datefrom text,
- dateto text,
- sapregion_id text,
- region text,
- sapcountry_id text,
- country text,
- sapplant_id text,
- plant text,
- sapcluster_id text,
- cluster text,
- sapitem_id text,
- itemname text,
- sapsupplier_id text,
- supplier text,
- currency text
- );
- execute format ($$copy itemdata
- from %L
- delimiter ';'
- header
- csv$$, $1);
- insert into "clusters_items" (sap_code,from_date,to_date)(select cast (sapcluster_id as integer), cast(datefrom as date), cast(dateto as date) from itemdata);
- insert into "plants" (sap_code)(select cast (sapplant_id as integer) from itemdata);
- insert into "items"(item_name,sap_code)(select itemname, cast(sapitem_id as integer)from itemdata);
- end;
- $body$
- language plpgsql;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement