githubEdit

Validate URL

The is_valid_url function checks whether a string is a well-formed URL with a scheme, authority (host), and optional port/path/query/fragment. Returns a BOOLEAN.

A valid URL must have:

  • A scheme (e.g., http, https, ftp, or any valid scheme)

  • The :// separator

  • A non-empty host (domain name, IPv4, or bracketed IPv6)

D SELECT is_valid_url('https://example.com') AS valid;
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  valid  β”‚
β”‚ boolean β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ true    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
D SELECT is_valid_url('https://example.com:8080/path?q=1#frag') AS valid;
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  valid  β”‚
β”‚ boolean β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ true    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
D SELECT is_valid_url('not a url') AS valid;
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  valid  β”‚
β”‚ boolean β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ false   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Returns NULL for NULL input.

Last updated

Was this helpful?