githubEdit

Extract Fragment

This function extracts the fragment (the part after #) from a URL. Fragments are commonly used for page anchors, single-page application routing, and deep linking.

D SELECT extract_fragment('http://example.com/page#section') AS fragment;
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ fragment β”‚
β”‚ varchar  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ section  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

D SELECT extract_fragment('http://example.com/path?q=1#results') AS fragment;
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ fragment β”‚
β”‚ varchar  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ results  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

D SELECT extract_fragment('http://example.com/#/users/123/profile') AS fragment;
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      fragment      β”‚
β”‚      varchar       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ /users/123/profile β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Returns an empty string if no fragment is present, and NULL for NULL input.

Last updated

Was this helpful?