Updated on 2026-11-06 GMT+08:00

parse_url

Returns the specified part of a given URL. Valid values for partToExtract are HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO. When the second parameter is QUERY, the third parameter can be used to extract the value of a specific parameter.

Syntax

parse_url(string <urlString>, string <partToExtract [, string <keyToExtract>]) 

Parameters

Parameter

Mandatory

Type

Description

urlString

Yes

STRING

URL.

partToExtract

Yes

STRING

Valid values are HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO. Case-insensitive.

keyToExtract

No

STRING

When partToExtract is QUERY, extracts the corresponding value based on the key.

Return Values

Returns a value of type STRING.

  • If urlString, partToExtract, or keyToExtract is NULL, NULL is returned.
  • If partToExtract is not a valid value, NULL is returned.

Example Code

Returns example.com.

select parse_url('file://username@example.com:666/over/there/index.dtb?type=animal&name=narwhal#nose', 'HOST'); 

Returns /over/there/index.dtb.

select parse_url('file://username@example.com:666/over/there/index.dtb?type=animal&name=narwhal#nose', 'PATH'); 

Returns animal.

select parse_url('file://username@example.com:666/over/there/index.dtb?type=animal&name=narwhal#nose', 'QUERY', 'type'); 

Returns nose.

select parse_url('file://username@example.com:666/over/there/index.dtb?type=animal&name=narwhal#nose', 'REF'); 

Returns file.

select parse_url('file://username@example.com:666/over/there/index.dtb?type=animal&name=narwhal#nose', 'PROTOCOL'); 

Returns username@example.com:666.

select parse_url('file://username@example.com:666/over/there/index.dtb?type=animal&name=narwhal#nose', 'AUTHORITY'); 

Returns username.

select parse_url('file://username@example.com:666/over/there/index.dtb?type=animal&name=narwhal#nose', 'USERINFO');