X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id E05B1310146 for ; Fri, 27 Jun 2003 02:47:53 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 63970-09 for ; Thu, 26 Jun 2003 23:47:43 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 04E5D310135 for ; Thu, 26 Jun 2003 23:47:43 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5R2lgQQ023575; Thu, 26 Jun 2003 22:47:42 -0400 (EDT) To: Bruno Wolff III Cc: Vinay , pgsql-admin@postgresql.org Subject: Re: Newbie question In-reply-to: <20030626203911.GA10461@wolff.to> References: <001c01c33c1d$843e0100$157a40c0@vinay> <20030626203911.GA10461@wolff.to> Comments: In-reply-to Bruno Wolff III message dated "Thu, 26 Jun 2003 15:39:11 -0500" Date: Thu, 26 Jun 2003 22:47:42 -0400 Message-ID: <23574.1056682062@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/315 X-Sequence-Number: 9306 Bruno Wolff III writes: >> I want the column to accept the column value which is absolutely length of two. > A char(2) will always have two characters (unless it is NULL). If you want > to check for two nonblank characters or two letters or something like > that use a check constraint. > Some like: > create table test ( > col1 char(2) constraint bad_length check (col1 ~ '^[a-zA-Z][a-zA-Z]$' > ); The most obvious way to my mind is check(length(rtrim(col1)) = 2) if "length" is simply defined as "number of characters excluding trailing blanks". If you want a more complex check then something like Bruno's example will probably get the job done. If you are going to apply a constraint like this then I'd counsel just declaring the column as text --- making it char(2) simply means that the system is applying an extra check that is redundant with your constraint. regards, tom lane