gen*_*bee 2 postgresql import date-format csv
软件:
Linux cjz-eshop1-p 5.4.0-33-generic #37-Ubuntu SMP Thu May 21 12:53:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
psql (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)
Run Code Online (Sandbox Code Playgroud)
由于将 CSV 导入我的服务器上的数据库,我收到错误。
ERROR: current transaction is aborted, commands ignored until end of transaction block
Price 244385 ERROR: date/time field value out of range: "30.06.2020"
Hint: Perhaps you need a different "datestyle" setting.
Position: 160
ERROR: current transaction is aborted, commands ignored until end of transaction block
Price 244386 ERROR: date/time field value out of range: "30.06.2020"
Hint: Perhaps you need a different "datestyle" setting.
Position: 160
Run Code Online (Sandbox Code Playgroud)
但在我的本地系统上,导入正常。
我尝试了关于这个问题的几乎所有方法,但没有运气(我大部分是从这里画的)。
有什么想法可以解决这个问题吗?
更新
导入是通过java
. 我相信这并不重要,因为在我的本地计算机上,它使用相同的操作系统和相同的配置。正如你所看到的,当我尝试select
与日期相关时(正如@Laurenz 帮助我的那样),这是可以的。
postgres@cjz-eshop1-p:~$ psql
psql (12.2 (Ubuntu 12.2-4))
Type "help" for help.
postgres=# SELECT '30.06.2020'::date;
date
------------
30.06.2020
(1 row)
postgres=#
Run Code Online (Sandbox Code Playgroud)
以前,这是不可能的。您想要更多详细信息吗?
更新2
if (body[5].length() != 0) {
akc_from = "'" + body[5] + "'";
} else {
akc_from = "null";
}
if (body[6].length() != 0) {
akc_to = "'" + body[6] + "'";
} else {
akc_to = "null";
}
if (body[7].length() != 0) {
akc_type = body[7];
} else {
akc_type = "null";
}
insertPriceCommand = "insert into stg_price(art_no,store_no,sell_pr,akc_price,akc_from,akc_to,akc_type,run_id,proc_flag,proc_note) values(" + art_no + "," + store_no + "," + sell_pr + "," + akc_price + "," + akc_from + "," + akc_to + "," + akc_type + "," + run_id + ",0,null)";
// System.out.println(insertPriceCommand);
```
Run Code Online (Sandbox Code Playgroud)
按照提示并datestyle
适当调整您的设置。
该参数由两部分组成:输出样式和日、月、年的预期顺序。
使用美国设置,解析30.06.2020
会导致错误:
SET datestyle = US, MDY;
SELECT '30.06.2020'::date;
ERROR: date/time field value out of range: "30.06.2020"
LINE 1: SELECT '30.06.2020'::date;
^
HINT: Perhaps you need a different "datestyle" setting.
Run Code Online (Sandbox Code Playgroud)
这是因为一年只有12个月。
您可能应该使用此设置:
SET datestyle = GERMAN, DMY;
SELECT '30.06.2020'::date;
date
------------
30.06.2020
(1 row)
Run Code Online (Sandbox Code Playgroud)
连接时可以使用options
连接参数来设置。datestyle