[pgsql-jp: 32093] Re: COPYコマンドによるtimestamp 型データのインポート

Shigehiro Honda fwif0083 @ mb.infoweb.ne.jp
2004年 1月 23日 (金) 02:29:06 JST


本田です。

From: 西尾大助 <d-nishio @ ta2.so-net.ne.jp>
Subject: [pgsql-jp: 32092] COPYコマンドによるtimestamp 型データのインポート
Date: Thu, 22 Jan 2004 23:48:00 +0900

> 元になるテキストデータは下記のような形式です。
> 22222233,15,1,20031025 14:30,,
> 00012919,04,1,20031105 09:54,,
  (略)
> 以下のエラーが表示されます。
>  Error: copy line 1, Bad timestamp external representation ''
> 元ファイルの日時の部分を'20031025 14:30'とシングルクオートで
> くくっても同様のエラーでした。
エラーメッセージを見ると、5列目の''をtimestamp型のカラムに入れ
ていそうだったので、ちょっと実験しました。予想通りでしたが、テー
ブル定義とCSVファイルの定義が合っているかチェックしてみて下さい。

だめだったら、テーブル定義情報など提示してください。

(1) バージョン7.3.3、7.4.1両方とも成功します。
postgres=# create table test (a int, b int, c int, d timestamp, e text, f text);
CREATE TABLE
postgres=# copy test from '/home/postgres/aaa.txt' DELIMITERS ',' WITH NULL AS '\null';
COPY
postgres=# select * from test
postgres-# ;
    a     | b  | c |          d          | e | f
----------+----+---+---------------------+---+---
 22222233 | 15 | 1 | 2003-10-25 14:30:00 |   |
    12919 |  4 | 1 | 2003-11-05 09:54:00 |   |
(2 rows)
postgres=# drop table test;
DROP TABLE

(2) テーブル定義を意図的に間違えると
バージョン7.3.3では、以下の結果になります。
honda=# create table test (a int, b int, c int, d text, e timestamp, f text);
CREATE TABLE
honda=# copy test from '/home/honda/aaa.txt' DELIMITERS ',' WITH NULL AS '\null';
ERROR:  copy: line 1, Bad timestamp external representation ''

バージョン7.4.1では、以下の結果になります。
postgres=# create table test (a int, b int, c int, d text, e timestamp, f text);
CREATE TABLE
postgres=# copy test from '/home/postgres/aaa.txt' DELIMITERS ',' WITH NULL AS '\null';
ERROR:  invalid input syntax for type timestamp: ""
CONTEXT:  COPY test, line 1, column e: ""



pgsql-jp メーリングリストの案内