Re: String manipulation - Mailing list pgsql-general

From Bruce Momjian
Subject Re: String manipulation
Date
Msg-id 200402172144.i1HLiS609434@candle.pha.pa.us
Whole thread Raw
In response to Re: String manipulation  (Pascal Polleunus <ppo@beeznest.net>)
Responses Re: String manipulation  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Pascal Polleunus wrote:
> You should be able to do that with a regular expression.
>
> CHECK (text ~ '^([0-9A-F]{2})+$')
>
> Remark: As the column is NOT NULL, I suppose that an empty string is not
> valid. If an empty string must be valid, replace the + with * ;-)

I just noticed an unusual affect.  GUC regex_flavor affects CHECK
constraints even after the check constraint has been created:

    test=> SET regex_flavor = 'advanced'; -- default
    SET
     ?column?
    ----------
     t
    (1 row)

    test=> SET regex_flavor = 'basic';
    SET
    test=> SELECT 'abc' ~ '(a|x).*';
     ?column?
    ----------
     f
    (1 row)

    test=> SET regex_flavor = 'advanced';
    SET
    test=> CREATE TABLE test (x TEXT CHECK (x ~ '(a|x).*'));
    CREATE TABLE
    test=> INSERT INTO test VALUES ('a');
    INSERT 17149 1
    test=> SET regex_flavor = 'basic';
    SET
    test=> INSERT INTO test VALUES ('a');
    ERROR:  new row for relation "test" violates check constraint "test_x"

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

pgsql-general by date:

Previous
From: Jan Poslusny
Date:
Subject: Re: Select statment question
Next
From: Peter Eisentraut
Date:
Subject: Re: Support.