Re: Domain check constraint not honored?

Поиск
Список
Период
Сортировка
От Rob Sargent
Тема Re: Domain check constraint not honored?
Дата
Msg-id 56325C2F.7040408@gmail.com
обсуждение исходный текст
Ответ на Domain check constraint not honored?  (Eric Schwarzenbach <subscriber@blackbrook.org>)
Ответы Re: Domain check constraint not honored?
Re: Domain check constraint not honored?
Список pgsql-general
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

В списке pgsql-general по дате отправления:

Предыдущее
От: Dane Foster
Дата:
Сообщение: mysql_fdw trouble
Следующее
От: Melvin Davidson
Дата:
Сообщение: Re: does pg_dump get delayed if I have a loop that does continuous insertions