2017-05-25 106 views
1

我有一个使用从Oracle存储过程生成的ASCII编码的CSV文件。错误:Postgresql中的日期/时间字段值超出范围

我需要默认set date to MDY

使用存储过程,可以导入CSV文件向Postgres数据库表,其中在Postgres里我曾尝试set datestyle to SQL,DMY;在Postgres的终端昨晚。

今天早上,当我看到datastyle格式的MDY格式。除非它在postgres.conf文件中配置,否则我不需要它,因为它适用于所有数据库。

所以我需要设置DATESTYLE在存储过程中

这里导入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; 
+0

我回滚到以前的版本,因为你没有编辑 - 你问了一个新问题。请问一个新来做 –

+0

这里是链接来设置datestyle永久https://dba.stackexchange.com/questions/19679/how-to-set-postgresql-database-to-see-date-as-mdy - 永久 –

+0

“所以我需要在存储过程中导入CSV文件时设置datestyle”?.. –

回答

2

脚本设置交易使用local配置。 https://www.postgresql.org/docs/current/static/sql-set.html

SESSION is the default if neither SESSION nor LOCAL appears

(粗体矿)

所以例如:

t=# begin; 
BEGIN 
t=# set local DateStyle to ISO,DMY; 
SET 
t=# show DateStyle; 
DateStyle 
----------- 
ISO, DMY 
(1 row) 
t=# end; 
COMMIT 
t=# show DateStyle; 
DateStyle 
----------- 
ISO, MDY 
(1 row) 

也介意你如何设置DATESTYLE - 这是对价值的。

https://www.postgresql.org/docs/current/static/runtime-config-client.html

DateStyle (string)

Sets the display format for date and time values, as well as the rules for interpreting ambiguous date input values. For historical reasons, this variable contains two independent components: the output format specification (ISO, Postgres, SQL, or German) and the input/output specification for year/month/day ordering (DMY, MDY, or YMD). These can be set separately or together. The keywords Euro and European are synonyms for DMY; the keywords US, NonEuro, and NonEuropean are synonyms for MDY. See Section 8.5 for more information. The built-in default is ISO, MDY, but initdb will initialize the configuration file with a setting that corresponds to the behavior of the chosen lc_time locale.

相关问题