I'm guessing it's because char gets padded with spaces to the specified
length.

Any reason you are using char(3) instead of varchar(3)?  And why are you
storing numbers as a string, anyway?  If you defined the column as a
numeric type, postgres will tell you if you try to insert something
non-numeric.

Dmitri

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Sebastian Siewior
Sent: Monday, August 15, 2005 6:20 PM
To: pgsql-sql@postgresql.org
Subject: [SQL] Problem with a Pettern Matching Check


Hello hopefully correct List,

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? :)

I was trying this one on PostgreSQL 8.0.3

-- 
Regards
Sebastian Siewior

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match
The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential and/or privileged material. Any 
review, retransmission, dissemination or other use of, or taking of any action 
in reliance upon, this information by persons or entities other than the 
intended recipient is prohibited. If you received this in error, please contact 
the sender and delete the material from any computer

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply via email to