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