Init scrips for postgres.

This commit is contained in:
Bill Thiede 2016-12-21 21:04:52 -08:00
parent 069ea6962a
commit f2ef02a033
2 changed files with 43 additions and 0 deletions

13
pg/list-ids.sql Normal file
View File

@ -0,0 +1,13 @@
SELECT
COUNT(value),
SUBSTRING(value from '(.*)<') AS name,
COALESCE(SUBSTRING(value from '<(.*)>'), value) AS id
FROM
header
WHERE
name = 'List-Id'
GROUP BY
value
ORDER BY
count DESC
;

30
pg/named-list-ids.sql Normal file
View File

@ -0,0 +1,30 @@
SELECT
DISTINCT ON(
LOWER(COALESCE(SUBSTRING(value from '<(.*)>'), value)))
COALESCE(named.count, 1),
LOWER(COALESCE(named.name,
LOWER(COALESCE(SUBSTRING(value from '<(.*)>'), value)))) AS id,
unnamed.name AS name
FROM
header unnamed
LEFT OUTER JOIN (
SELECT
DISTINCT ON (LOWER(COALESCE(SUBSTRING(value from '<(.*)>'), value)))
COUNT(value) AS count,
SUBSTRING(value from '(.*)<') AS name,
LOWER(COALESCE(SUBSTRING(value from '<(.*)>'), value)) AS id
FROM
header
WHERE
name != ''
GROUP BY
LOWER(COALESCE(SUBSTRING(value from '<(.*)>'), value)),
SUBSTRING(value from '(.*)<')
ORDER BY
id,
count DESC,
name
) named
ON
named.id = LOWER(COALESCE(SUBSTRING(unnamed.value from '<(.*)>'), unnamed.value))
;