Re: BUG #17352: Column CHECK regex error - Mailing list pgsql-bugs

From Vik Fearing
Subject Re: BUG #17352: Column CHECK regex error
Date
Msg-id 7b75d6b6-f44e-6380-19cf-35736666e24b@postgresfriends.org
Whole thread Raw
In response to BUG #17352: Column CHECK regex error  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
On 1/3/22 11:38 AM, PG Bug reporting form wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      17352
> Logged by:          Serge Salamatin
> Email address:      salamsp@gmail.com
> PostgreSQL version: 13.5
> Operating system:   Ubuntu 13.5-2.pgdg20.04+1
> Description:        
> 
> select '01' ~ '^[\d-]{2,8}$'  -> true, 
> 
> but in next
> 
> CREATE TABLE IF NOT EXISTS public.mnu
> (
>     mnunm character(10) COLLATE pg_catalog."default" NOT NULL,
>     code character(8) COLLATE pg_catalog."default" NOT NULL
>       CONSTRAINT "Only digits" CHECK (code ~ '^[\d-]{2,8}$'),

The bug here is that you are using the character(n) type, which you
shouldn't.  That type has archaic (but standard) behavior that pads the
value with spaces.  Your regex does not account for that.

Don't use that type.  Use text instead.

https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_char.28n.29

-- 
Vik Fearing



pgsql-bugs by date:

Previous
From: Francisco Olarte
Date:
Subject: Re: BUG #17352: Column CHECK regex error
Next
From: Etsuro Fujita
Date:
Subject: Re: BUG #17344: Assert failed on queiring async_capable foreign table with inheritance