【问题标题】:oracle to postgres, DATE field is in error while insertingoracle 到 postgres,插入时 DATE 字段出错
【发布时间】:2018-04-04 03:43:00
【问题描述】:
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。

我尝试对选择查询进行类型化,但未能成功。

在提取数据时,我尝试在下面对该日期(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

有什么提示吗?

【问题讨论】:

  • 为什么你认为转换查询的列会影响插入语句?你明白错误信息吗?

标签: sql postgresql timestamp postgresql-9.4


【解决方案1】:

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

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

【讨论】:

  • 考希克,感谢您的回复。我正在运行选择查询,然后使用外部工具插入。我无法修改插入查询。我试图通过在选择查询本身中连接时间戳来获得类似的输出,但它的输出类似于 '0002-05-05 00:00:00.0 :: TIMESTAMP' 而不是 '0002-05-05 00:00:00.0' :: TIMESTAMP
  • @Jay : 请显示您尝试获取该输出的选择查询
  • @Jay 请将此评论的信息合并到您的帖子中。没有人能猜到你不能修改插入语句。
【解决方案2】:
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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 2015-09-12
    • 2014-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多