Re: Problem with a Pettern Matching Check - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: Problem with a Pettern Matching Check
Date
Msg-id 20050815224208.GA51332@winnie.fuhr.org
Whole thread Raw
In response to Problem with a Pettern Matching Check  (Sebastian Siewior <lavish@kamp-dsl.de>)
Responses Re: Problem with a Pettern Matching Check  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
On Tue, Aug 16, 2005 at 12:19:50AM +0200, Sebastian Siewior wrote:
>
> 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? :)

The CHAR(3) specification causes the value to be space-padded, so
'1' becomes '1  ' (the digit "one" followed by two spaces).  See
"Character Types" in the documentation:

http://www.postgresql.org/docs/8.0/static/datatype-character.html

Do you have a reason for using a character type instead of a numeric
type like integer?

-- 
Michael Fuhr


pgsql-sql by date:

Previous
From: Andreas Seltenreich
Date:
Subject: Re: Problem with a Pettern Matching Check
Next
From: Sebastian Siewior
Date:
Subject: Re: Problem with a Pettern Matching Check