-- 一時テーブルはCSVの全カラムを持つテーブルで、コミットしたら消される
DROP TABLE IF EXISTS work_csv;
CREATE TEMP TABLE work_csv (
    create_record_date timestamp without time zone,
    line_id	integer,
    line_name text,
    basic_parts_no text,
    work_date date,
    af_amount integer,
    we_amount integer,
    kd_we_amount integer,
    production_lur integer,
    model_cd text,
    derivation text,
    tact_time integer
);
-- ON COMMIT DROP;
-- SPLIT --
COPY work_csv FROM STDIN WITH (FORMAT CSV, HEADER);
-- SPLIT --
INSERT
INTO
    vap.t_weorder
    (
        create_record_date,
        line_id,
        basic_parts_no,
        plan_date,
        af_amount,
        we_amount,
        production_lur,
        model_cd,
        derivation,
        tact_time
    )
    SELECT
        create_record_date,
        line_id,
        basic_parts_no,
        work_date,
        af_amount,
        we_amount + kd_we_amount,
        production_lur,
        model_cd,
        derivation,
        tact_time
    FROM
        work_csv;
