Postgres で URL を解析できません。顧客と顧客に関連付けられた URL でいっぱいのデータベースがあります。各顧客に関連付けられた一意のドメインの配列が必要です。結果をPythonにダンプしてそこで解析するのではなく、クエリで解析できるようにしたいと思っています。
postgres docs でこれを見つけましたが、それをクエリに組み込む方法がわかりません:
SELECT alias, description, token FROM ts_debug('http://example.com/stuff/index.html');
alias | description | token
----------+---------------+------------------------------
protocol | Protocol head | http://
url | URL | example.com/stuff/index.html
host | Host | example.com
url_path | URL path | /stuff/index.html
( http://www.postgresql.org/docs/9.3/static/textsearch-parsers.html )
次のようなテーブルから始めます。
customer_id | url
-------------+--------------------
000001 | www.example.com/fish
000001 | www.example.com/potato
000001 | www.potato.com/artichoke
000002 | www.otherexample.com
これまでの私のコード:
SELECT customer_id, array_agg(url)
FROM customer_url_table
GROUP BY customer_id
それは私に与えます:
customer_id | unique_domains
-----------------------------
000001 | {www.example.com/fish, www.example.com/potato, www.potato.com/greenery}
000002 | {www.otherexample.com}
次のようなテーブルが必要です。
customer_id | unique_domains
-----------------------------
000001 | {example.com, potato.com}
000002 | {otherexample.com}
AWS にある PostgreSQL 9.3.3 データベースでの作業。