PG date类型插入数据说明


datastyle格式为DMY或者MDY时,允许以YMD的格式插入数据;
但datastyle格式为YMD时,不允许以DMY或者MDY的格式插入数据;

postgres9.6@[local]:5432 postgres# create table t (coll date);
CREATE TABLE
Time: 10.555 ms
postgres9.6@[local]:5432 postgres# show datestyle;
 DateStyle 
-----------
 ISO, MDY
(1 row)

Time: 0.518 ms


postgres9.6@[local]:5432 postgres# insert into t values(date '2016-12-15');
INSERT 0 1
Time: 4.225 ms
postgres9.6@[local]:5432 postgres# select * from t;
    coll    
------------
 2016-12-15
(1 row)
Time: 0.646 ms
postgres9.6@[local]:5432 postgres# insert into t values(date '12-15-2016');
INSERT 0 1
Time: 2.720 ms
postgres9.6@[local]:5432 postgres# insert into t values(date '15-12-2016');
ERROR:  date/time field value out of range: "15-12-2016"
LINE 1: insert into t values(date '15-12-2016');
                                  ^
HINT:  Perhaps you need a different "datestyle" setting.
Time: 0.591 ms


postgres9.6@[local]:5432 postgres# set datestyle='DMY';
SET
Time: 0.827 ms
postgres9.6@[local]:5432 postgres# insert into t values(date '15-12-2016');
INSERT 0 1
Time: 3.200 ms
postgres9.6@[local]:5432 postgres# insert into t values(date '2016-12-15');
INSERT 0 1
Time: 2.884 ms
postgres9.6@[local]:5432 postgres# insert into t values(date '12-15-2016');
ERROR:  date/time field value out of range: "12-15-2016"
LINE 1: insert into t values(date '12-15-2016');
                                  ^
HINT:  Perhaps you need a different "datestyle" setting.
Time: 0.761 ms
postgres9.6@[local]:5432 postgres# set datestyle='YMD';
SET
Time: 0.306 ms
postgres9.6@[local]:5432 postgres# insert into t values(date '2016-12-15');
INSERT 0 1
Time: 2.611 ms
postgres9.6@[local]:5432 postgres# insert into t values(date '12-15-2016');
ERROR:  date/time field value out of range: "12-15-2016"
LINE 1: insert into t values(date '12-15-2016');
                                  ^
HINT:  Perhaps you need a different "datestyle" setting.
Time: 1.523 ms
postgres9.6@[local]:5432 postgres# insert into t values(date '15-12-2016');
ERROR:  date/time field value out of range: "15-12-2016"
LINE 1: insert into t values(date '15-12-2016');
                                  ^
HINT:  Perhaps you need a different "datestyle" setting.
Time: 1.465 ms
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值