Skip to content

Add domain_depth function#22

Merged
hatamiarash7 merged 1 commit intomainfrom
domain-depth
Feb 21, 2026
Merged

Add domain_depth function#22
hatamiarash7 merged 1 commit intomainfrom
domain-depth

Conversation

@hatamiarash7
Copy link
Owner

Implements domain_depth(VARCHAR) → INTEGER — returns the number of dot-separated levels (labels) in a domain name. Extracts the host from full URLs automatically.

Examples

SELECT domain_depth('example.com');              -- 2
SELECT domain_depth('https://www.example.com');  -- 3
SELECT domain_depth('a.b.c.example.co.uk');      -- 6
SELECT domain_depth('localhost');                 -- 1
SELECT domain_depth('192.168.1.1');              -- 0 (IP address)

Behavior

  • Extracts the host from full URLs (with scheme, port, path, query, fragment) before counting
  • Returns the number of dot-separated labels: www.example.com → 3
  • Returns 0 for IPv4 and IPv6 addresses (not domains)
  • Returns 0 for empty strings and invalid input
  • Returns 1 for single-label names like localhost
  • Returns NULL for NULL input
  • Strips trailing DNS dots before counting (example.com. → 2)
  • Case-insensitive

@hatamiarash7 hatamiarash7 merged commit 5b42244 into main Feb 21, 2026
5 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant