Re: newbie: Column CHECK(col contains '@') ?

From: "Joel Burton" <joel(at)joelburton(dot)com>
To: "john-paul delaney" <jp(at)justatest(dot)com>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: newbie: Column CHECK(col contains '@') ?
Date: 2002-05-12 19:50:50
Message-ID: JGEPJNMCKODMDHGOBKDNEEMCCNAA.joel@joelburton.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

> One column in my table contains email addresses - I want to check
> that any value entered contains a '@'. How do I create a
> CONSTRAINT or CHECK to ensure this when creating the table?

create table em (
em text constraint is_email check (em like '%(at)%(dot)%')
);

will work fine, assuming that this check (something @ something . something)
is acceptable in your context as "looks like an email address"

- J.

Joel BURTON | joel(at)joelburton(dot)com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message john-paul delaney 2002-05-12 23:21:05 Re: newbie: Column CHECK(col contains '@') ?
Previous Message G 2002-05-12 19:24:17 Selecting random rows using weights