Re: constraint question

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: constraint question
Дата
Msg-id 19293.978304367@sss.pgh.pa.us
обсуждение исходный текст
Ответ на constraint question  (mwaples@optusnet.com.au)
Список pgsql-novice
mwaples@optusnet.com.au writes:
> I have table users with a varchar field user_name,
> Id like to restrict this to just alphanumeric characters
> can I do this with a check constraint ?

Sure, use a regexp pattern match, eg

regression=# create table fooey (f1 text check (f1 ~ '^[A-Za-z0-9]*$'));
CREATE
regression=# insert into fooey values('zzz33');
INSERT 145186 1
regression=# insert into fooey values('zzz 33');
ERROR:  ExecAppend: rejected due to CHECK constraint fooey_f1
regression=#

The pattern match operators are not very well documented in the 7.0
docs, but see
http://www.postgresql.org/devel-corner/docs/postgres/functions-matching.htm

            regards, tom lane

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

Предыдущее
От: mwaples@optusnet.com.au
Дата:
Сообщение: Re: constraint question
Следующее
От: "Brett W. McCoy"
Дата:
Сообщение: Re: constraint question