X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 08228D1D388 for ; Tue, 2 Dec 2003 09:27:41 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 81717-05 for ; Tue, 2 Dec 2003 05:27:11 -0400 (AST) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id 7F272D1D38A for ; Tue, 2 Dec 2003 05:27:07 -0400 (AST) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Tue Dec 02 10:27:05 2003 +0100 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id KAA15468; Tue, 2 Dec 2003 10:27:05 +0100 (MET) From: Christoph Haller Message-Id: <200312020927.KAA17321@rodos> Subject: Re: Validity check in to_date? To: fduch@antar.bryansk.ru (Alexander M. Pravking) Date: Tue, 02 Dec 2003 10:27:04 MET Cc: pgsql-sql@postgresql.org In-Reply-To: <20031127141125.GC87728@dyatel.antar.bryansk.ru>; from "Alexander M. Pravking" at Nov 27, 103 3:15 pm X-Mailer: Elm [revision: 212.4] X-Virus-Scanned: by amavisd-new at postgresql.org X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char 9C hex) in message header 'Received' Received: \234by rodos.fzk.de... ^ X-Archive-Number: 200312/11 X-Sequence-Number: 16177 > > I just discovered that to_date() function does not check if supplied > date is correct, giving surprising (at least for me) results: > > fduch=# SELECT to_date('31.11.2003', 'DD.MM.YYYY'); > to_date > ------------ > 2003-12-01 > > or even > > fduch=# SELECT to_date('123.45.2003', 'DD.MM.YYYY'); > to_date > ------------ > 2007-01-03 > > to_timestamp() seems to work the same way. It's probably useful sometimes, > but not in my case... Is it how it supposed to work? > If so, how can I do such a validity check? > If not, has something changed in 7.4? > > In any case, I have to find a workaround now and will appreciate any help. > > > fduch=# SELECT version(); > version > --------------------------------------------------------------------- > PostgreSQL 7.3.4 on i386-portbld-freebsd4.8, compiled by GCC 2.95.4 > > > -- > Fduch M. Pravking > As far as I know these results are correct in terms of the underlying C-library function mktime(). This function is intended to be used when adding/subtracting intervals from a given timestamp. I don't know of any postgres function doing the check you're looking for. But I can't believe this is the first time this topic is brought up. You may search the archives on "date plausibility" are related terms. HTH Regards, Christoph