postgresql 获取错误错误:日期/时间字段值超出范围:“Postgres 中的 31 APR 2001

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6174077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:02:56  来源:igfitidea点击:

Getting error ERROR: date/time field value out of range: "31 APR 2001 in Postgres

sqlpostgresql

提问by Elitmiar

I have a varchar field where dates are stored in the database where I need data from with values like 31 APR 2001I run the following query

我有一个 varchar 字段,其中日期存储在数据库中,我需要来自31 APR 2001等值的数据我运行以下查询

select date(trim(contact_date)) from clients where date(trim(contact_date)) < '2002-03-12';

select date(trim(contact_date)) from clients where date(trim(contact_date)) < '2002-03-12';

Whenever it hits 31 APR 2001 I get the error ERROR: date/time field value out of range: "31 APR 2001

每当它到达 2001 年 4 月 31 日时,我都会收到错误错误: 日期/时间字段值超出范围:“2001 年 4 月 31 日

Are there any workaround so that I won't get this error. Since all other dates get return perfectly.

是否有任何解决方法,以便我不会收到此错误。由于所有其他日期都可以完美返回。

The version of postgres I use is PostgreSQL 8.1.22

我使用的 postgres 版本是 PostgreSQL 8.1.22

回答by mechanical_meat

There are 30 days in the month of April.

四月有30天。

回答by Nighil

there is no 31 in April month, prevent it from hitting 31 check it before query

4月份没有31,防止打到31,查询前查一下