Skip to main content
Returns a URL that is the same as the current page’s URL, but with a variable set to a new value.

Signature

sqlpage.set_variable(name TEXT, value TEXT) -> TEXT

Parameters

name
TEXT
required
The name of the variable to set
value
TEXT
The value to set (NULL removes the variable)

Return Value

return
TEXT
URL with the modified parameter

Description

The set_variable() function creates links that modify one parameter while preserving all others. Useful for filters, pagination, and sorting.

Examples

Filter Buttons

SELECT 'button' as component;
SELECT 
    category as title,
    sqlpage.set_variable('category', category) as link,
    CASE WHEN $category = category THEN 'primary' ELSE 'secondary' END as color
FROM categories;

Pagination

SELECT 'button' as component;
SELECT 
    'Next Page' as title,
    sqlpage.set_variable('page', CAST(COALESCE($page, 1) + 1 AS TEXT)) as link;

Build docs developers (and LLMs) love