Skip to main content
Encodes a string for safe use in URLs using percent-encoding.

Signature

sqlpage.url_encode(text TEXT) -> TEXT

Parameters

text
TEXT
The string to encode

Return Value

return
TEXT
URL-encoded string, or NULL if input is NULL

Description

The url_encode() function converts special characters to percent-encoded format, making strings safe for URLs.

Examples

Encode Search Query

SET search = :user_search;
SET url = 'https://example.com/search?q=' || sqlpage.url_encode($search);

SELECT 'text' as component,
    '<a href="' || $url || '">Search Results</a>' as html;
SELECT 'list' as component;
SELECT 
    title,
    'article.sql?title=' || sqlpage.url_encode(title) as link
FROM articles;

Encoding Examples

InputOutput
hello worldhello%20world
user@example.comuser%40example.com
a&b=ca%26b%3Dc
20% off!20%25%20off%21

Build docs developers (and LLMs) love