Relative Content

Tag Archive for sqlregexpostgresql

Extract Main Domain from URLs in PostgreSQL Without Subdomains, Ports, or Query Parameters

I’m working with a PostgreSQL query where I need to extract the main domain (including the second-level domain and top-level domain) from URLs. However, the current approach using REGEXP_MATCH or SUBSTRING doesn’t handle all cases correctly. For example, it fails to parse URLs like {www.paylink.fr:443} (which should be paylink.fr) and {api.ornage.com} (which should be ornage.com)