如何通过存储的函数导入CSV文件?

时间:2016-05-10 12:52:19

标签: postgresql

我有包含10条记录的示例CSV文件。

所以我想通过存储过程上传CSV文件。 是否有可能这样做。这是我存储的功能。

FOR i IN 1..v_cnt LOOP

    SELECT idx_date,file_path INTO v_idx_date,v_file_path FROM cloud10k.temp_idx_dates
    WHERE is_updated IS FALSE LIMIT 1;

    COPY cloud10k.temp_master_idx_new(header_section) FROM v_file_path;

    DELETE FROM cloud10k.temp_master_idx_new WHERE header_section NOT ILIKE '%.txt%';

    UPDATE cloud10k.temp_master_idx_new SET CIK          = split_part( header_section,'|',1),
                                            company_name = split_part( header_section,'|',2),
                                            form_type    = split_part( header_section,'|',3),
                                            date_filed   = split_part( header_section,'|',4)::DATE,
                                            accession_number = replace(split_part(split_part( header_section,'|',5),'/',4),'.txt',''),
                                            file_path    = to_char(SUBSTRING(SPLIT_PART(v_file_path,'master.',2) FROM 1 FOR 8)::DATE,'YYYY')
   ||'/'||to_char(SUBSTRING(SPLIT_PART(v_file_path,'master.',2) FROM 1 FOR 8)::DATE,'MM')
   ||'/'||to_char(SUBSTRING(SPLIT_PART(v_file_path,'master.',2) FROM 1 FOR 8)::DATE,'DD')
   ||'/'||CONCAT_WS('.','master',SPLIT_PART(v_file_path,'master.',2) )

    WHERE header_section ILIKE '%.txt%';
 END LOOP;

但它没有执行。有人可以建议我怎么做..

坦克, 拉梅什

0 个答案:

没有答案