X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 88996D1B44F for ; Wed, 26 Nov 2003 05:42:56 +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 91344-05 for ; Wed, 26 Nov 2003 01:42:26 -0400 (AST) Received: from millenium.mst.co.jp (unknown [210.230.185.241]) by svr1.postgresql.org (Postfix) with ESMTP id 20192D1B438 for ; Wed, 26 Nov 2003 01:42:25 -0400 (AST) Received: from mst1x5r347kymb (lc12114 [192.168.1.114]) by millenium.mst.co.jp (8.11.6p2/3.7W) with SMTP id hAQ5Wri08936; Wed, 26 Nov 2003 14:32:53 +0900 Message-ID: <00a201c3b3df$e84b8c50$7201a8c0@mst1x5r347kymb> From: "Iain" To: "Bruno Wolff III" Cc: References: <000901c3b315$47f41710$7201a8c0@mst1x5r347kymb> <20031125172606.GB25043@wolff.to> <001c01c3b3bb$63ebcd40$7201a8c0@mst1x5r347kymb> <20031126052313.GA2524@wolff.to> Subject: Re: A quick question about domains Date: Wed, 26 Nov 2003 14:41:15 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/452 X-Sequence-Number: 11439 > > Also, this is a rework of an existing system and dates are stored as > > strings. I don't like it but I'm stuck with it for now. I was hoping to be > > able to provide some DB level validation of the dates as 'YYYY-MM-DD' but I > > havn't come across a neat way to do it yet. I also hope that domains might > > facilitate a smooth change to date type dates someday in the future (in my > > dreams, i guess). In the mean time, if anyone knows a 'neat' way to validate > > the date strings I'd be happy to hear about it. I got bogged down in very > > much over involved (an probably slow) code that couldn't guarantee a valid > > date anyway. The date conversion function to_date is far too forgiving to > > fulfill this purpose, it seems. > > You can use a check constraint with a regular expression. It would look > something like like: > check (datecolumnname ~ '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$') > That just checks for digits in the right place, it doesn't tightly > bound the range of the numbers. Nice idea, I hadn't thought of that. It's somewhat tidier than my original experiment. I think it's about time I learnt a little more about regular expressions. I'll check it out. Thanks for your input, I appreciate it. Regards iain