githubEdit

Extract Path Segments

The extract_path_segments table function splits a URL path into individual segment rows. Each row contains a 1-based segment_index and the segment string. This is useful for analyzing URL structures, filtering by path depth, or joining path components.

D SELECT * FROM extract_path_segments('https://example.com/path/to/page?q=1');
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ segment_index β”‚ segment β”‚
β”‚     int32     β”‚ varchar β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚             1 β”‚ path    β”‚
β”‚             2 β”‚ to      β”‚
β”‚             3 β”‚ page    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
D SELECT * FROM extract_path_segments('https://api.example.com/v3/users/42/repos');
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ segment_index β”‚ segment β”‚
β”‚     int32     β”‚ varchar β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚             1 β”‚ v3      β”‚
β”‚             2 β”‚ users   β”‚
β”‚             3 β”‚ 42      β”‚
β”‚             4 β”‚ repos   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

LATERAL Join

Use with LATERAL to expand path segments per row in a table:

Returns 0 rows for URLs with no path, root path (/), empty strings, and NULL input.

Last updated

Was this helpful?