Re: newbie: Column CHECK(col contains '@') ? - Mailing list pgsql-novice

From Joel Burton
Subject Re: newbie: Column CHECK(col contains '@') ?
Date
Msg-id JGEPJNMCKODMDHGOBKDNEEMCCNAA.joel@joelburton.com
Whole thread Raw
In response to newbie: Column CHECK(col contains '@') ?  (john-paul delaney <jp@justatest.com>)
Responses Re: newbie: Column CHECK(col contains '@') ?  (john-paul delaney <jp@justatest.com>)
List 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 '%@%.%')
);

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@joelburton.com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant


pgsql-novice by date:

Previous
From: "G"
Date:
Subject: Selecting random rows using weights
Next
From: john-paul delaney
Date:
Subject: Re: newbie: Column CHECK(col contains '@') ?