Skip to content

Instantly share code, notes, and snippets.

@pstef
Last active August 29, 2015 13:56
Show Gist options
  • Save pstef/9238780 to your computer and use it in GitHub Desktop.
Save pstef/9238780 to your computer and use it in GitHub Desktop.
<lluad> Is there a tidier way to get the last two components of a hostname than (regexp_matches(foo, '\.([^.]+\.[^.]+)$'))[1] ? It works, but kinda offends even me. It's only going to be used on hostnames, so I don't really care what it does to non-hostname input.
SELECT array_to_string(a[array_upper(a, 1)-1:array_upper(a, 1)], '.')
FROM string_to_array('gist.github.com', '.') a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment