sql_analysis
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
sql_analysis [2010/08/12 22:52] – created daniel | sql_analysis [2016/07/21 04:00] – [Presence and count of specific mail headers] daniel | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | | + | |
+ | This query extracts, for each of the header fields from a fixed list, the number of occurrences of all distinct values of the field. | ||
<code sql> | <code sql> | ||
Line 7: | Line 8: | ||
FROM header, (values (' | FROM header, (values (' | ||
WHERE position(E' | WHERE position(E' | ||
- | group by split_part(substr(lines, | + | group by 1 |
</ | </ | ||
+ | |||
+ | Sample output: | ||
+ | < | ||
+ | ct | count | ||
+ | ---------------------------+------- | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | This alternative implementation uses regular expressions and differs in that it doesn' | ||
+ | <code sql> | ||
+ | select FIELD||':' | ||
+ | from (select FIELD, regexp_matches(lines, | ||
+ | from header, | ||
+ | | ||
+ | | ||
+ | where strpos(lines, | ||
+ | GROUP BY 1 ORDER BY 1 | ||
+ | </ | ||
+ | |||
+ | In this version, the '' | ||
+ | ====== Duplicate messages ====== | ||
+ | This query finds each message that share the exact same headers than another message with a lower mail_id, which means that it's a duplicate. | ||
+ | <code sql> | ||
+ | select h1.mail_id from header h1, header h2 where h1.lines=h2.lines and h1.mail_id > h2.mail_id | ||
+ | </ | ||
+ | |||
+ | ====== Messages with specific attachment types ====== | ||
+ | To retrieve all messages containing pdf files or any image file: | ||
+ | <code sql> | ||
+ | select distinct mail_id FROM attachments WHERE content_type=' | ||
+ | </ | ||
+ | |||
+ | ====== Messages sent or received today ====== | ||
+ | < | ||
+ | select mail_id from mail where msg_date> | ||
+ | </ | ||
+ | |||
sql_analysis.txt · Last modified: 2019/01/24 17:55 by daniel