Re: Problem with a Pettern Matching Check

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Sebastian Siewior <lavish(at)kamp-dsl(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Problem with a Pettern Matching Check
Date: 2005-08-15 22:42:08
Message-ID: 20050815224208.GA51332@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Seltenreich 2005-08-15 22:43:28 Re: Problem with a Pettern Matching Check
Previous Message Dmitri Bichko 2005-08-15 22:37:52 Re: Problem with a Pettern Matching Check