X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id F220D9FB1C0 for ; Sat, 8 Jul 2006 03:35:06 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 77264-01 for ; Sat, 8 Jul 2006 03:34:58 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31810.mail.mud.yahoo.com (web31810.mail.mud.yahoo.com [68.142.207.73]) by postgresql.org (Postfix) with SMTP id 4A42D9FB1B8 for ; Sat, 8 Jul 2006 03:34:58 -0300 (ADT) Received: (qmail 56832 invoked by uid 60001); 8 Jul 2006 06:34:57 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=B+1jBEUv2tkT7Z4ieWDN+f+L83rDqkv/jYdXA85tO/FjBBjRdrQ5v9AyPlrcejStm57E8kGX8mbcGLOWJV4fKHe/fp+qohZihqJiKnvDREU4jf9At6tg3KX0L5/yAwWtkNJ6CMzEpZHfoyjWd13UTi/KJIwqxXkOeflw7JCfeqU= ; Message-ID: <20060708063457.56830.qmail@web31810.mail.mud.yahoo.com> Received: from [24.54.196.198] by web31810.mail.mud.yahoo.com via HTTP; Fri, 07 Jul 2006 23:34:57 PDT Date: Fri, 7 Jul 2006 23:34:57 -0700 (PDT) From: Richard Broersma Jr Subject: Celko's Puzzle Number 5 To: SQL Postgresql List MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/126 X-Sequence-Number: 25700 No matter how I try it, I can't getting the book's answer for this puzzle to work. Does anyone know of a solution that will work for this problem. The Problem is: "How do you ensure that a column will have a single alphabetic character string in it? (That means no spaces, no numbers, and no special characters.)" The book's solution is as follows: CREATE TABLE Foobar (alpha_only VARCHAR(6) CHECK ((UPPER(TRIM(alpha_only)) || 'AAAAA') BETWEEN 'AAAAAA' AND 'ZZZZZZ') ); However, this check constraint only prevents numerics beginning with 'A'. So the constraint works by preventing following strings that begin with these kinds of characters: !...., 4...., A!..., A4... But the constraint fails to prevent non-alphabetic characters when the string starts with a character > A. Thus B thru Z can be follow on not alphabetic characters. I compared the result from PostgreSQL with sqlite and access. They returned the same result. According to the text, this solution "could" have been generalized to work with more complicated strings as well. For example string "masks" could be used to enforce a kind of tagging convention like 'AA44444', 'BB55555'. Has anyone seen or done anything like this before? I am interested to hear what kind of solutions there are. Regards, Richard Broersma Jr.