【发布时间】:2017-05-25 05:48:26
【问题描述】:
我有一个从 Oracle 存储过程生成的 ASCII 编码的 CSV 文件。
我需要使用存储过程将 CSV 文件导入 Postgres 数据库表,默认情况下在 postgres 中 set date to MDY
我昨晚确实尝试在 postgres 终端中set datestyle to SQL,DMY;。
今天早上,当我看到 datastyle 格式为 MDY 格式时。除非它在 postgres.conf 文件中配置,但我不需要它,因为它适用于所有数据库。
所以我需要在存储过程中导入CSV文件时设置日期样式
这是 Postgres 的脚本
begin
set schema 'public';
raise notice 'CSV PATH: %,TABLE NAME: %',csv_path,target_table;
execute format('truncate %I ',target_table);
execute format('copy %I from %L WITH (FORMAT csv)',target_table, csv_path);
return;
end;
【问题讨论】:
-
我回滚到以前的版本,因为你没有编辑它 - 你问了一个新问题。请让新人这样做
-
这里是永久设置日期样式的链接dba.stackexchange.com/questions/19679/…
-
“所以我需要在存储过程中导入CSV文件时设置日期样式”?...
-
我认为在不准确的不同方法中最好使用数据库命令
标签: postgresql csv stored-procedures stored-functions