Skip to main content
Returns the path component of the URL for the current request.

Signature

sqlpage.path() -> TEXT

Parameters

This function takes no parameters.

Return Value

return
TEXT
The URL-encoded path of the current request (e.g., /my%20page.sql)

Description

The path() function returns the path portion of the current request URL. This is useful for:
  • Generating links to the current page
  • Handling proxy URL rewrites
  • Building navigation based on the current location
  • Creating self-referencing forms
The returned path is URL-encoded, so spaces become %20, etc.

Examples

Self-Referencing Form

Create a form that submits to the current page:
SELECT 'form' as component,
    sqlpage.path() as action;

SELECT 'search' as name,
    'text' as type,
    'Search...' as placeholder;

Highlight Current Page in Navigation

Build a navigation menu that highlights the current page:
SELECT 'shell' as component,
    'My Website' as title,
    json_array(
        json_object(
            'title', 'Home',
            'link', '/index.sql',
            'active', sqlpage.path() = '/index.sql'
        ),
        json_object(
            'title', 'About',
            'link', '/about.sql',
            'active', sqlpage.path() = '/about.sql'
        ),
        json_object(
            'title', 'Contact',
            'link', '/contact.sql',
            'active', sqlpage.path() = '/contact.sql'
        )
    ) as menu_item;

Filter by Page Section

Use path to show different content based on the current page:
SET current_path = sqlpage.path();

SELECT 'text' as component,
    'Admin Dashboard' as title
WHERE $current_path LIKE '/admin/%';

SELECT 'text' as component,
    'User Area' as title
WHERE $current_path LIKE '/user/%';
Generate breadcrumbs based on the current path:
SET current_path = sqlpage.path();

SELECT 'breadcrumb' as component;
SELECT 
    UPPER(SUBSTR(path_part, 1, 1)) || SUBSTR(path_part, 2) as title,
    path_part as link
FROM (
    SELECT 
        value as path_part,
        row_number() OVER () as pos
    FROM json_each(json_array($current_path))
);
Create links that modify parameters while staying on the same page:
SELECT 'button' as component;
SELECT 
    'Filter: ' || category as title,
    sqlpage.link(
        sqlpage.path(),
        json_object('category', category)
    ) as link
FROM categories;

Working with Proxies

When behind a reverse proxy that rewrites URLs:
-- The path is relative to the SQLPage application,
-- not the proxy's URL structure
SET app_path = sqlpage.path();

SELECT 'debug' as component;
SELECT 'Current path' as title, $app_path as description;

Path Format

  • Starts with /
  • URL-encoded (spaces = %20, etc.)
  • Includes file extension (.sql)
  • Does NOT include query string (use sqlpage.variables('get') for parameters)
  • Does NOT include hash/fragment

Example Paths

URLsqlpage.path()
http://example.com/page.sql/page.sql
http://example.com/my page.sql/my%20page.sql
http://example.com/admin/users.sql?id=5/admin/users.sql
http://example.com//index.sql

See Also

Build docs developers (and LLMs) love