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
SinceEMAILADDR
is a specialized type, queries can be performed as with standard text columns:
Validating Email Format
Theemailaddr
type ensures that only valid email addresses are stored. For example, the following insertion will fail:
'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
Theemailaddr
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.