Skip to content

Instantly share code, notes, and snippets.

@oskarpearson
Last active July 14, 2016 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oskarpearson/0c365dd5d25667bf7b1a9094bcded868 to your computer and use it in GitHub Desktop.
Save oskarpearson/0c365dd5d25667bf7b1a9094bcded868 to your computer and use it in GitHub Desktop.
Some inconsistencies with detection of email addresses in postgres
# select version();
version
-------------------------------------------------------------------------------------------------
PostgreSQL 9.5.3 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit
(1 row)
# SELECT email, to_tsvector('simple', email) FROM (
VALUES ('foo@example.com'), ('foo+123@example.com'),
('123+foo@example.com'), ('123+123foo@example.com'),
('foo123@example.com'), ('foo_123@example.com'),
('foo__123@example.com')
) as t (email);
email | to_tsvector
------------------------+--------------------------------------
foo@example.com | 'foo@example.com':1
foo+123@example.com | '+123':2 'example.com':3 'foo':1
123+foo@example.com | '123':1 'foo@example.com':2
123+123foo@example.com | '+123':2 '123':1 'foo@example.com':3
foo123@example.com | 'foo123@example.com':1
foo_123@example.com | 'foo_123@example.com':1
foo__123@example.com | '123':2 'example.com':3 'foo':1
# select ts_debug('foo@example.com');
ts_debug
---------------------------------------------------------------------------
(email,"Email address",foo@example.com,{simple},simple,{foo@example.com})
(1 row)
# select ts_debug('foo+123@example.com');
ts_debug
---------------------------------------------------------------------
(asciiword,"Word, all ASCII",foo,{english_stem},english_stem,{foo})
(int,"Signed integer",+123,{simple},simple,{+123})
(blank,"Space symbols",@,{},,)
(host,Host,example.com,{simple},simple,{example.com})
(4 rows)
# select ts_debug('123+foo@example.com');
ts_debug
---------------------------------------------------------------------------
(uint,"Unsigned integer",123,{simple},simple,{123})
(blank,"Space symbols",+,{},,)
(email,"Email address",foo@example.com,{simple},simple,{foo@example.com})
(3 rows)
# select ts_debug('123+123foo@example.com');
ts_debug
---------------------------------------------------------------------------
(uint,"Unsigned integer",123,{simple},simple,{123})
(int,"Signed integer",+123,{simple},simple,{+123})
(email,"Email address",foo@example.com,{simple},simple,{foo@example.com})
(3 rows)
# select ts_debug('foo123@example.com');
ts_debug
---------------------------------------------------------------------------------
(email,"Email address",foo123@example.com,{simple},simple,{foo123@example.com})
(1 row)
# select ts_debug('foo_123@example.com');
ts_debug
-----------------------------------------------------------------------------------
(email,"Email address",foo_123@example.com,{simple},simple,{foo_123@example.com})
(1 row)
# select ts_debug('foo__123@example.com');
ts_debug
---------------------------------------------------------------------
(asciiword,"Word, all ASCII",foo,{english_stem},english_stem,{foo})
(blank,"Space symbols",__,{},,)
(uint,"Unsigned integer",123,{simple},simple,{123})
(blank,"Space symbols",@,{},,)
(host,Host,example.com,{simple},simple,{example.com})
(5 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment