From: | Rob Sargent <robjsargent(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Domain check constraint not honored? |
Date: | 2015-10-29 19:27:06 |
Message-ID: | 5632730A.6050803@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 10/29/2015 12:29 PM, Eric Schwarzenbach wrote:
>
> Thank you! (Slapping head)
> Your regexp seems to do the trick.
>
> On 10/29/2015 01:49 PM, Rob Sargent wrote:
>> On 10/29/2015 11:41 AM, Eric Schwarzenbach wrote:
>>> I have created a custom type as a domain based on text, which adds a
>>> check constraint using a regexp to limit it to containing digits and
>>> '.'. However I am finding I can add values with other characters to
>>> a column of this type. Is this to be expected for some reason?
>>>
>>> Or alternately, did I define the constraint wrong somehow? It is
>>> defined thus:
>>>
>>> CREATE DOMAIN hierpath AS text
>>> CHECK(
>>> VALUE ~ '[0-9.]+'
>>> );
>>>
>>> Checking the docs I'm pretty sure the '.' doesn't need escaping but
>>> I also tried a test leaving it out ( '[0-9]+') and the result is the
>>> same. It lets me store letters in a column defined to be of this type.
>>>
>>> The version() function tells me
>>> "PostgreSQL 9.4.5 on x86_64-unknown-linux-gnu, compiled by gcc
>>> (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit"
>>>
>>> Thanks,
>>> Eric
>>>
>>>
>> I think you regexp is too weak. So long as the value has a digit or
>> period, it's good.
>> '^[0-9.]+$' might work
>
Cool.
Note that this is a bottom-post forum and unfortunately so imho. Please
don't top post.
Also thought I should mention that there is an ip address type if that's
what you're trying to accomplish.
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2015-10-29 19:30:43 | Re: mysql_fdw trouble |
Previous Message | Tom Lane | 2015-10-29 19:14:32 | Re: Configure Different Databases on One Server |