pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vik Fearing <vik@postgresfriends.org>
To: salamsp@gmail.com
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17352: Column CHECK regex error
Date: Mon, 3 Jan 2022 12:16:21 +0100
Message-ID: <7b75d6b6-f44e-6380-19cf-35736666e24b@postgresfriends.org> (raw)
In-Reply-To: <17352-7564a4d9c118056d@postgresql.org>
References: <17352-7564a4d9c118056d@postgresql.org>

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





view thread (3+ messages)

Message-ID: <7b75d6b6-f44e-6380-19cf-35736666e24b@postgresfriends.org>
Permalink:  ../7b75d6b6-f44e-6380-19cf-35736666e24b@postgresfriends.org/
Also on:    postgresql.org/message-id/7b75d6b6-f44e-6380-19cf-35736666e24b@postgresfriends.org

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: vik@postgresfriends.org, salamsp@gmail.com
  Subject: Re: BUG #17352: Column CHECK regex error
  In-Reply-To: <7b75d6b6-f44e-6380-19cf-35736666e24b@postgresfriends.org>
  References: <17352-7564a4d9c118056d@postgresql.org> <7b75d6b6-f44e-6380-19cf-35736666e24b@postgresfriends.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