Created
April 7, 2016 01:44
-
-
Save bjeanes/d51e111f6c004f0b6ec05971ac1b86ce to your computer and use it in GitHub Desktop.
Email domain type for postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE EXTENSION IF NOT EXISTS citext; | |
| -- http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690 | |
| CREATE DOMAIN email AS citext | |
| CHECK ( | |
| VALUE IS NULL OR ( | |
| -- is not more than 254 chars | |
| length(VALUE) <= 254 AND | |
| -- vaguely looks like an email address | |
| VALUE ~ '.@.' AND | |
| -- local part is not more than 64 chars | |
| length(split_part(VALUE, '@', 1)) <= 64 AND | |
| -- domain part is not more than 255 chars | |
| length(split_part(VALUE, '@', 2)) <= 255 | |
| ) | |
| ); |
Author
Author
https://github.com/petere/pgemailaddr would be even better, but not currently available on Heroku's Postgres offering.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Field type allows for
nullvalues because the column in a table can still beNOT NULLif need be.