| From: | "Brett W(dot) McCoy" <bmccoy(at)chapelperilous(dot)net> |
|---|---|
| To: | <mwaples(at)optusnet(dot)com(dot)au> |
| Cc: | <pgsql-novice(at)postgresql(dot)org> |
| Subject: | Re: constraint question |
| Date: | 2000-12-31 23:48:17 |
| Message-ID: | Pine.LNX.4.30.0012311847080.21590-100000@chapelperilous.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
On Mon, 1 Jan 2001 mwaples(at)optusnet(dot)com(dot)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!"
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Brett W. McCoy | 2001-01-01 17:09:10 | Re: Blob question -((( |
| Previous Message | Tom Lane | 2000-12-31 23:12:47 | Re: constraint question |