Not sure of the exact problem you are trying to solve; is it just querying the table via domain name? Does the index that you created work? A few things; the regex given does not get domain name for some valid emails addresses; i.e. foo@bar@xxxxxxxxxxx is a valid email; however, the regex _expression_ would return bar@xxxxxxxxxxx instead of nowhere.com. create or replace function get_domainname(_value text) returns text as $$ begin _value := reverse(_value); return nullif(reverse(substring(_value, 0, strpos(_value, '@'))), ''); end; $$ language plpgsql immutable returns null on null input ; create index table_name_idx1 on table_name (get_domainname(email)); Then in the where clause: where get_domainname(email) = 'nowhere.com' p.s. If you want to validate that the email address conforms to the RFC 2822 you can use this function which makes use of Perl’s Email::Address module. You would need to install plperl and Email::Address module. create or replace function is_valid_email_address(eaddr text) returns boolean as $body$ use Email::Address; return Email::Address->parse($_[0]); $body$ language 'plperlu' immutable ; |