X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 585A452EE3 for ; Mon, 15 Aug 2005 19:43:34 -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 48022-05 for ; Mon, 15 Aug 2005 22:43:30 +0000 (GMT) Received: from smtp1.rz.uni-karlsruhe.de (smtp1.rz.uni-karlsruhe.de [129.13.185.217]) by svr1.postgresql.org (Postfix) with ESMTP id CFFA052E9C for ; Mon, 15 Aug 2005 19:43:29 -0300 (ADT) Received: from rzstud1.stud.uni-karlsruhe.de (rzstud1.stud.uni-karlsruhe.de [193.196.41.33]) by smtp1.rz.uni-karlsruhe.de with esmtp (Exim 4.43 #1) id 1E4ng2-0005CX-Sr; Tue, 16 Aug 2005 00:43:30 +0200 Received: from uwi7 by rzstud1.stud.uni-karlsruhe.de with local (Exim 3.36 #1) id 1E4ng3-0007Gl-00; Tue, 16 Aug 2005 00:43:31 +0200 From: Andreas Seltenreich To: Sebastian Siewior Cc: pgsql-sql@postgresql.org Subject: Re: Problem with a Pettern Matching Check References: <20050816001950.2225e5b8@mikejones.ghb.fh-furtwangen.de> X-Now-Playing: Ulver / Nattens Madrigal X-Face: $:F<87a[gD1?#R6S3j21cr1&C&7bd63GHC.tSdskUb}hhwG(ci*=D5kJ<_N+p9q(7-, PnG. Et.Yh (Sebastian Siewior's message of "Tue, 16 Aug 2005 00:19:50 +0200") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Message-ID: <877jemg6sv.fsf@gate450.dyndns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200508/100 X-Sequence-Number: 22328 Sebastian Siewior schrob: > Hello hopefully correct List, perfectly. > I was trying to do something that is not working as it supposed to. > First I created a table: > > create table t ( > col CHAR (3) CONSTRAINT numonly_col CHECK ( col ~ '^\\d+$' ) > ); > > This check avoids non-numbers like '1a1' and allows '123'. For some > reason, I'm unable to find out why, it also avoids things like '1' and > '12'. Could someone please give me hint? :) Char is padded with spaces, and that is also why your regexp is not matching in these situations. You could either adjust your regexp to match the trailing spaces or use varchar(3) instead: --8<---------------cut here---------------start------------->8--- scratch=# select '1'::char(3) ~ '^\\d+$'; ?column? ---------- f (1 row) scratch=# select '1'::char(3) ~ '^\\d+\\s*$'; ?column? ---------- t (1 row) scratch=# select '1'::varchar(3) ~ '^\\d+$'; ?column? ---------- t (1 row) --8<---------------cut here---------------end--------------->8--- regards Andreas --