Re: constraint question

Поиск
Список
Период
Сортировка
От Brett W. McCoy
Тема Re: constraint question
Дата
Msg-id Pine.LNX.4.30.0012311847080.21590-100000@chapelperilous.net
обсуждение исходный текст
Ответ на constraint question  (mwaples@optusnet.com.au)
Список pgsql-novice
On Mon, 1 Jan 2001 mwaples@optusnet.com.au wrote:

> 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 ?
> or do I need to use a tigger and function ?

Use a regular expression in your check constraint:

create table reg_test (
        id integer primary key,
        descr varchar(20),
        check (descr ~* '^[A-Z0-9]*$')
);

insert into reg_test values (1, 'data\&');
ERROR:  ExecAppend: rejected due to CHECK constraint $1

-- Brett
                                     http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
Feeling amorous, she looked under the sheets and cried, "Oh, no,
it's Microsoft!"


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: constraint question
Следующее
От: Boris
Дата:
Сообщение: Blob question -(((