From: Michael Fuhr <mike@fuhr.org>
To: Sebastian Siewior <lavish@kamp-dsl.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: Problem with a Pettern Matching Check
Date: Mon, 15 Aug 2005 16:42:08 -0600
Message-ID: <20050815224208.GA51332@winnie.fuhr.org> (raw)
In-Reply-To: <20050816001950.2225e5b8@mikejones.ghb.fh-furtwangen.de>
References: <20050816001950.2225e5b8@mikejones.ghb.fh-furtwangen.de>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mike@fuhr.org, lavish@kamp-dsl.de
Subject: Re: Problem with a Pettern Matching Check
In-Reply-To: <20050815224208.GA51332@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox