PostgreSQL TO_DATE 查询问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9789576/
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:44:40 来源:igfitidea点击:
PostgreSQL TO_DATE query issue
提问by Psyche
I have the following PostgreSQL query:
我有以下 PostgreSQL 查询:
INSERT INTO persoane_alocate(pa_id_pj,pa_id_corespondent_persoana,pa_procentaj,pa_tip_persoana,pa_data_inceput,pa_data_sfarsit,pa_afisare_in_monitor,audit_data_modificarii,audit_id_utilizator) VALUES ('670', '534', '0', '1', CASE 0000-00-00 WHEN 0 THEN NULL ELSE TO_DATE('30 Nov -0001', 'YYYY-MM-DD') END, CASE 2007-02-12 WHEN 0 THEN NULL ELSE TO_DATE('12 Feb 2007', 'YYYY-MM-DD') END, '2', '2012-03-20 17:11:34', 9999)
And I get the following error:
我收到以下错误:
Query failed: ERROR: invalid value "Fe" for "MM" DETAIL: Value must be an integer.
Any ideas about how to fix it?
关于如何修复它的任何想法?
Thanks.
谢谢。
回答by Mariusz Jamro
You have:
你有:
to_date('12 Feb 2007', 'YYYY-MM-DD')
instead of:
代替:
to_date('12 Feb 2007', 'DD Mon YYYY')
So you're trying to parse date using wrong format. See the reference.
所以你试图用错误的格式解析日期。请参阅参考资料。