Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. create or replace function carica_item(_file_path text)
  2. returns void as
  3. $body$
  4. begin
  5.  
  6. drop table if exists itemdata;
  7. CREATE temp TABLE itemdata
  8. (
  9. datefrom text,
  10. dateto text,
  11. sapregion_id text,
  12. region text,
  13. sapcountry_id text,
  14. country text,
  15. sapplant_id text,
  16. plant text,
  17. sapcluster_id text,
  18. cluster text,
  19. sapitem_id text,
  20. itemname text,
  21. sapsupplier_id text,
  22. supplier text,
  23. currency text
  24. );
  25.  
  26. execute format ($$copy itemdata
  27. from %L
  28. delimiter ';'
  29. header
  30. csv$$, $1);
  31.  
  32. 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);
  33. insert into "plants" (sap_code)(select cast (sapplant_id as integer) from itemdata);
  34. insert into "items"(item_name,sap_code)(select itemname, cast(sapitem_id as integer)from itemdata);
  35.  
  36.  
  37. end;
  38. $body$
  39. language plpgsql;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement