to_char() accepting invalid dates?

Поиск
Список
Период
Сортировка
Искать

to_char() accepting invalid dates?

От:
Thomas Kellerer <spam_eater@gmx.net>
Дата:
Hi,

I just noticed that to_char() will "accept" invalid dates such as 2011-02-31 and "adjust" them accordingly:

postgres=> select to_date('20110231', 'yyyymmdd');  to_date
------------ 2011-03-03
(1 row)

is there a way to have to_date() raise an exception in such a case?

Regards
Thomas


Re: to_char() accepting invalid dates?

От:
Jasen Betts <jasen@xnet.co.nz>
Дата:
On 2011-07-18, Thomas Kellerer  wrote:
> Hi,
>
> I just noticed that to_char() will "accept" invalid dates such as 2011-02-31 and "adjust" them accordingly:
>
> postgres=> select to_date('20110231', 'yyyymmdd');
>
>    to_date
> ------------
>   2011-03-03
> (1 row)
>
> is there a way to have to_date() raise an exception in such a case?

it's possible the odd behaviour you get is required by some standard.
however 'yyyymmdd' is a format that postgres understands natively,
so just cast the string to date.
jasen=# select '20110303'::date;    date     ------------  2011-03-03  (1 row)	    jasen=# select '20110231'::date;ERROR:  date/time field value out of range: "20110231"LINE 1: select '20110231'::date;                ^

postgres also understands YYYY-MM-DD and possilby a locale 
dependant form with the year last 	    
-- 
⚂⚃ 100% natural


Re: to_char() accepting invalid dates?

От:
Thomas Kellerer <spam_eater@gmx.net>
Дата:
Jasen Betts wrote on 18.07.2011 11:23:
>> postgres=>  select to_date('20110231', 'yyyymmdd');
>>
>>     to_date
>> ------------
>>    2011-03-03
>> (1 row)
>>
>> is there a way to have to_date() raise an exception in such a case?
>
> it's possible the odd behaviour you get is required by some standard.

That would be *very* odd indeed.


>   jasen=# select '20110303'::date;
Thanks for the tip, this was more a question regarding _why_ to_char() behaves this way.

Thomas


Re: to_char() accepting invalid dates?

От:
Bruce Momjian <bruce@momjian.us>
Дата:
Thomas Kellerer wrote:
> Jasen Betts wrote on 18.07.2011 11:23:
> >> postgres=>  select to_date('20110231', 'yyyymmdd');
> >>
> >>     to_date
> >> ------------
> >>    2011-03-03
> >> (1 row)
> >>
> >> is there a way to have to_date() raise an exception in such a case?
> >
> > it's possible the odd behaviour you get is required by some standard.
> 
> That would be *very* odd indeed.
> 
> 
> >   jasen=# select '20110303'::date;
> Thanks for the tip, this was more a question regarding _why_ to_char() behaves this way.

Well, to_char() is based on Oracle's to_char().  How does Oracle handle
such a date?

--  Bruce Momjian          http://momjian.us EnterpriseDB                             http://enterprisedb.com
 + It's impossible for everything to be true. +

Re: to_char() accepting invalid dates?

От:
Thomas Kellerer <spam_eater@gmx.net>
Дата:
Bruce Momjian, 19.07.2011 00:02:
>>>> postgres=>   select to_date('20110231', 'yyyymmdd');
>>>>
>>>>      to_date
>>>> ------------
>>>>     2011-03-03
>>>> (1 row)
>>>>
>>>> is there a way to have to_date() raise an exception in such a case?
>>>
>>> it's possible the odd behaviour you get is required by some standard.
>>
>> That would be *very* odd indeed.
>>
>>
>>>    jasen=# select '20110303'::date;
>> Thanks for the tip, this was more a question regarding _why_ to_char() behaves this way.
>
> Well, to_char() is based on Oracle's to_char().  How does Oracle handle
> such a date?

Oracle throws an error for the above example:

SQL> select to_date('20110231', 'YYYYMMDD') from dual;
select to_date('20110231', 'YYYYMMDD') from dual               *
ERROR at line 1:
ORA-01839: date not valid for month specified

SQL>


Regards
Thomas
 



Re: to_char() accepting invalid dates?

От:
"Igor Neyman" <ineyman@perceptron.com>
Дата:


-----Original Message-----
From: Bruce Momjian [mailto:bruce@momjian.us] 
Sent: Monday, July 18, 2011 6:02 PM
To: Thomas Kellerer
Cc: pgsql-sql@postgresql.org
Subject: Re: to_char() accepting invalid dates?

Thomas Kellerer wrote:
> Jasen Betts wrote on 18.07.2011 11:23:
> >> postgres=>  select to_date('20110231', 'yyyymmdd');
> >>
> >>     to_date
> >> ------------
> >>    2011-03-03
> >> (1 row)
> >>
> >> is there a way to have to_date() raise an exception in such a case?
> >
> > it's possible the odd behaviour you get is required by some
standard.
> 
> That would be *very* odd indeed.
> 
> 
> >   jasen=# select '20110303'::date;
> Thanks for the tip, this was more a question regarding _why_ to_char()
behaves this way.

> Well, to_char() is based on Oracle's to_char().  How does Oracle
handle
> such a date?

> -- 
>   Bruce Momjian          http://momjian.us
>   EnterpriseDB                             http://enterprisedb.com

>   + It's impossible for everything to be true. +


This (from Oracle) makes me think, that it's implemented differently:

Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

SQL> select to_date('20110231', 'yyyymmdd') from dual;
select to_date('20110231', 'yyyymmdd') from dual              *
ERROR at line 1:
ORA-01839: date not valid for month specified


SQL>


Regards,
Igor Neyman

Re: to_char() accepting invalid dates?

От:
Bruce Momjian <bruce@momjian.us>
Дата:
Thomas Kellerer wrote:
> Bruce Momjian, 19.07.2011 00:02:
> >>>> postgres=>   select to_date('20110231', 'yyyymmdd');
> >>>>
> >>>>      to_date
> >>>> ------------
> >>>>     2011-03-03
> >>>> (1 row)
> >>>>
> >>>> is there a way to have to_date() raise an exception in such a case?
> >>>
> >>> it's possible the odd behaviour you get is required by some standard.
> >>
> >> That would be *very* odd indeed.
> >>
> >>
> >>>    jasen=# select '20110303'::date;
> >> Thanks for the tip, this was more a question regarding _why_ to_char() behaves this way.
> >
> > Well, to_char() is based on Oracle's to_char().  How does Oracle handle
> > such a date?
> 
> Oracle throws an error for the above example:
> 
> SQL> select to_date('20110231', 'YYYYMMDD') from dual;
> select to_date('20110231', 'YYYYMMDD') from dual
>                 *
> ERROR at line 1:
> ORA-01839: date not valid for month specified
> 
> SQL>

OK, it's a bug then.  Let me see if I can find a fix for it.

--  Bruce Momjian          http://momjian.us EnterpriseDB                             http://enterprisedb.com
 + It's impossible for everything to be true. +

Re: to_char() accepting invalid dates?

От:
Thomas Kellerer <spam_eater@gmx.net>
Дата:
Bruce Momjian, 20.07.2011 03:03:
>>> Well, to_char() is based on Oracle's to_char().  How does Oracle handle
>>> such a date?
>>
>> Oracle throws an error for the above example:
>>
>> SQL>  select to_date('20110231', 'YYYYMMDD') from dual;
>> select to_date('20110231', 'YYYYMMDD') from dual
>>                  *
>> ERROR at line 1:
>> ORA-01839: date not valid for month specified
>>
>> SQL>
>
> OK, it's a bug then.  Let me see if I can find a fix for it.

Thanks for the info. I didn't know it was modelled after the Oracle implementation.

Regards
Thomas
 



compile postgres with visual studio 2010

От:
"Sofer, Yuval" <Yuval_Sofer@bmc.com>
Дата:
Hi 

I would like to build Postgres from source with the visual studio 2010 compiler

Is it supported? Is there any document which describes the process of the implementation? 

Thanks, 


Yuval Sofer
BMC Software
CTM&D Business Unit
DBA Team
972-52-4286-282
yuval_sofer@bmc.com

Re: compile postgres with visual studio 2010

От:
Kevin Crain <kevin.crain1@gmail.com>
Дата:
The documentation only mentions Visual Studio 2005 and Visual Studio
2008, but I see no reason why it shouldn't work.  Check out the
requirements listed in the documentation:
http://www.postgresql.org/docs/9.0/interactive/install-windows-full.html

On Wed, Jul 20, 2011 at 3:55 AM, Sofer, Yuval  wrote:
> Hi
>
> I would like to build Postgres from source with the visual studio 2010 compiler
>
> Is it supported? Is there any document which describes the process of the implementation?
>
> Thanks,
>
>
> Yuval Sofer
> BMC Software
> CTM&D Business Unit
> DBA Team
> 972-52-4286-282
> yuval_sofer@bmc.com
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

Re: to_char() accepting invalid dates?

От:
"THOMPSON, JARED (ATTBAPCO)" <JT060b@ATT.COM>
Дата:

ERROR at line 1:

ORA-01839: date not valid for month specified

 

 

That error is coming on

select to_date('20110231', 'YYYYMMDD') from dual;

 

because there are not 31 days in February 2011, try this:

 

select to_date('20110228', 'YYYYMMDD') from dual;

 

Jared Thompson

Internet Operations Group

Office: 678.406.2895

jt060b@att.com

 

 

This e-mail and any files transmitted with it are AT&T property, are confidential, and are intended solely for the use of the individual or entity to whom this email is addressed. If you are not one of the named recipient(s) or otherwise have reason to believe that you have received this message in error, please notify the sender and delete this message immediately from your computer. Any other use, retention, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited.

 

FAQ