2017-05-25 35 views
1

Oracleストアドプロシージャから生成されたASCIIエンコーディングのCSVファイルがあります。エラー:PostgreSQLの日付/時刻フィールド値が範囲外です

は、私は、端末の最後の夜のpostgresにset datestyle to SQL,DMY;にしようとしなかったデフォルトset date to MDY

によってどこのpostgresにストアドプロシージャを使用してPostgresのDBのテーブルにCSVファイルをインポートする必要があります。

今日私は、データストアフォーマットMDYフォーマットを参照しています。それはpostgres.confファイルで設定されていない限りですが、すべてのデータベースに適用できるため、そこには必要ありません。

だから私はここでは、ストアドプロシージャに

をCSVファイルをインポートする時にDATESTYLEを設定する必要があり、トランザクションの使用localための設定を設定するには、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

データスタイルを永続的に設定するリンクは次のとおりです。https://dba.stackexchange.com/questions/19679/how-to-set-postgresql-database-to-see-date-as-mdy -permanently –

+0

"ストアドプロシージャでCSVファイルをインポートするときにdatestyleを設定する必要がありますか?" –

答えて

2

でスクリプトです。 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.

関連する問題