X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 53E2DDA3C1 for ; Thu, 6 Oct 2005 15:32:15 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25190-03 for ; Thu, 6 Oct 2005 18:32:07 +0000 (GMT) Received: from smtp103.rog.mail.re2.yahoo.com (smtp103.rog.mail.re2.yahoo.com [206.190.36.81]) by svr1.postgresql.org (Postfix) with SMTP id 3B1ECDA38F for ; Thu, 6 Oct 2005 15:32:04 -0300 (ADT) Received: (qmail 60371 invoked from network); 6 Oct 2005 18:15:14 -0000 Received: from unknown (HELO phlogiston.dydns.org) (a.sullivan@rogers.com@216.75.167.195 with login) by smtp103.rog.mail.re2.yahoo.com with SMTP; 6 Oct 2005 18:15:14 -0000 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 4B0EC4173; Thu, 6 Oct 2005 14:15:12 -0400 (EDT) Date: Thu, 6 Oct 2005 14:15:12 -0400 From: Andrew Sullivan To: pgsql-sql@postgresql.org Subject: Re: DATESTYLE and 0000-00-00 Message-ID: <20051006181512.GG28948@phlogiston.dyndns.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.04 required=5 tests=[AWL=-0.010, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/61 X-Sequence-Number: 22914 On Thu, Oct 06, 2005 at 09:01:22AM -0400, Joshua Kramer wrote: > I have my DATESTYLE set to ISO MDY. > > When I try to create a table with a default date of 0000-00-00, psql says > that this is an invalid date. Why, and can (or how can I) get it to > accept 0000-00-00 as a valid date? You can't. There's no year 0. As the docs say, if you don't like that, please complain to the Vatican; we can't help you. If you are trying to say, "Date unknown," you can use NULL (and maybe add another field to indicate whether the NULL means "no date" or "date unknown"). Note that your datestyle has nothing to do with this: Postgres won't let you put an invalid date into a date field. This also has the happy consequence that you can't accidentally create leap years where there aren't any: andrewtest=# SELECT '2005-02-29'::date; ERROR: date/time field value out of range: "2005-02-29" If you really think you have to have such dates, you are probably mistaken. If you have to have them because some application you can't control relies on them, you could store them in a text column, and coerce them to dates when you select (but be prepared for the errors you'll get). But my suggestion is that if you really think you have to have such dates, you should redesign (which might mean "replace") your application. Anything that uses dates with a year 0 is so fundamentally mistaken about how dates work that I wouldn't trust it. -- Andrew Sullivan | ajs@crankycanuck.ca In the future this spectacle of the middle classes shocking the avant- garde will probably become the textbook definition of Postmodernism. --Brad Holland