Emailaddr
Provides a specialized data type for storing and validating email addresses.
The emailaddr extension in PostgreSQL provides a specialized data type for storing and validating email addresses. This extension ensures proper email formatting and allows efficient querying.
Your Nile database arrives with emailaddr
extension already installed and enabled.
Creating and Populating contacts
Table
Before using emailaddr
, let’s create a sample table to store email addresses of key contacts:
Querying Email Addresses
Since EMAILADDR
is a specialized type, queries can be performed as with standard text columns:
Validating Email Format
The emailaddr
type ensures that only valid email addresses are stored. For example, the following insertion will fail:
This will result in an error because 'not_an_email'
is not a properly formatted email address.
Limitations
EMAILADDR
ensures correct email formatting but does not verify if the email exists.- Cannot store internationalized email addresses using Unicode.
Removing an Index
If you need to remove the index:
Conclusion
The emailaddr
extension in PostgreSQL simplifies email validation and storage while ensuring efficient indexing for lookup queries.
For more details, refer to the official PostgreSQL documentation or community resources.