oracle to postgres,插入时DATE字段出错

时间:2018-04-04 03:43:01

标签: sql postgresql timestamp postgresql-9.4

INSERT INTO ASSOCIATE_MERCHANT_INFO(start_date,end_date)  
VALUES ('0002-05-05 00:00:00.0',NULL)

结果:

Caused by: org.postgresql.util.PSQLException: 
ERROR: column "start_date" is of type timestamp without time zone but
    expression is of type character varying
[junit]   Hint: You will need to rewrite or cast the expression.

我可以在这里看到'0002-05-05 00:00:00.0'被postgres查询视为char。

我试图对select查询进行类型化,但未能取得成功。

在提取数据时,我在下面尝试将此日期(start_date)字段进行类型转换,如下所示:

  1. select cast(start_date as timestamp) as start_date
  2. select TO_TIMESTAMP(start_date) as start_date
  3. select TO_DATE(TO_CHAR(end_date, 'YYYY/MM/DD HH:MI:SS'), 'YYYY/MM/DD HH:MI:SS') as start_date
  4. 任何提示?

2 个答案:

答案 0 :(得分:0)

您是否尝试在插入时将其强制转换为TIMESTAMP

INSERT INTO associate_merchant_info
            (start_date,
             end_date)
VALUES  ('0002-05-05 00:00:00.0' :: TIMESTAMP,
             NULL);  

答案 1 :(得分:0)

INSERT INTO ASSOCIATE_MERCHANT_INFO(start_date,end_date) 
VALUES (to_timestamp('0002-05-05 00:00:00.0', 'YYYY-MM-DD HH24:MI:SS.MS'),NULL);