1

I need to upload a *.tsv file of the form File_[currentDate]_[currentMonth]_name.tsv. I've tried many ways, sadly in vain, I have to ask for the delimiter, or else the way to do this right:

SELECT CURRENT_DATE AS today;
SELECT EXTRACT(MONTH FROM TIMESTAMP 'today') AS MONTH;
SELECT EXTRACT(DAY FROM TIMESTAMP 'today') AS DAY;

COPY table_name FROM 'D:\File_**<DAY>**_**<MONTH>**_name.tsv' DELIMITER '   ' CSV header;

I'm expecting the Input file name to be File_19_04_name.tsv (today). What am I doing wrong? Any alternatives to do it right?

4

1 に答える 1

1

COPYplpgsql 関数内でコマンドを動的にビルドして実行します。

create or replace function cp()
returns text language plpgsql as $function$
begin
    execute $$
        COPY t
        FROM '$1'
        DELIMITER '   '
        CSV header
    $$ using 'D:\File_' || to_char(current_date, 'DD_MM') || '_name.tsv';
end;
$function$;

$1渡されたパラメータに置き換えられますusing

于 2013-04-19T12:26:45.640 に答える