Skip to main content
The debug component displays any set of values as formatted JSON. It’s invaluable for understanding what data is being passed to components during development.

Basic Usage

Replace any component name with debug to see all its parameters:
SELECT 'debug' AS component,
    TRUE AS my_top_level_property;

SELECT 'y' AS x, 42 AS z;
SELECT 'b' AS a, NULL AS c;
This displays:
{
  "component": "debug",
  "my_top_level_property": true
}
{
  "x": "y",
  "z": 42
}
{
  "a": "b",
  "c": null
}

Debugging SQLPage Functions

Inspect the output of SQLPage functions:
SELECT 'debug' AS component, sqlpage.environment_variable('HOME');
SELECT 'debug' AS component, sqlpage.request_info();
SELECT 'debug' AS component, 
    sqlpage.cookie('session_token') AS session,
    sqlpage.path() AS current_path,
    sqlpage.request_method() AS method;

Debugging Query Results

See exactly what your queries return:
SELECT 'debug' AS component;
SELECT * FROM users WHERE id = :user_id;
This helps verify:
  • Column names and types
  • NULL vs empty strings
  • Numeric precision
  • JSON structure

Debugging Form Submissions

Inspect all posted parameters:
SELECT 'debug' AS component,
    :username AS username,
    :email AS email,
    :age AS age,
    :newsletter AS newsletter;
Or use variables:
SELECT 'debug' AS component, sqlpage.variables('post');

Debugging Complex JSON

When working with JSON data, debug helps verify structure:
SELECT 'debug' AS component;
SELECT 
    json_object(
        'name', name,
        'items', (
            SELECT json_group_array(
                json_object('id', id, 'price', price)
            )
            FROM order_items
            WHERE order_items.order_id = orders.id
        )
    ) AS order_data
FROM orders
WHERE id = :order_id;

Debugging Component Properties

Verify properties before passing to dynamic component:
-- Instead of this:
-- SELECT 'dynamic' AS component, properties;

-- Debug first:
SELECT 'debug' AS component, properties
FROM (
    SELECT json_array(
        json_object('component', 'card'),
        json_object('title', 'Test', 'description', 'Test card')
    ) AS properties
);

Comparing Actual vs Expected Data

Debug side-by-side comparisons:
SELECT 'debug' AS component;

-- What we're sending
SELECT 
    'Expected' AS type,
    'John Doe' AS name,
    100 AS amount;

-- What the database has
SELECT 
    'Actual' AS type,
    name,
    amount
FROM transactions
WHERE id = :transaction_id;

Debugging Authentication

Check authentication values:
SELECT 'debug' AS component,
    sqlpage.basic_auth_username() AS username,
    sqlpage.basic_auth_password() AS password,
    :password AS form_password,
    (SELECT password_hash FROM users WHERE username = :username) AS stored_hash;

Debugging URL Parameters

See all URL parameters:
SELECT 'debug' AS component, sqlpage.variables('get');
Or specific parameters:
SELECT 'debug' AS component,
    $id AS id_param,
    $page AS page_param,
    $filter AS filter_param;

Production Safety

Never deploy pages with debug components to production. They expose internal data and can reveal sensitive information.

Conditional Debug

Only show debug info to admins:
-- Show debug only for admin users
SELECT 'debug' AS component, sqlpage.request_info()
WHERE :is_admin = '1';

-- Or based on environment
SELECT 'debug' AS component, sqlpage.request_info()
WHERE sqlpage.environment_variable('ENVIRONMENT') = 'development';

Common Debugging Scenarios

Empty Results

Why is my list empty?
-- Instead of list, use debug
SELECT 'debug' AS component;
SELECT * FROM products WHERE category = :category;
Check if:
  • Query returns any rows
  • Column names match expectations
  • Data types are correct
  • NULL values are present

Form Not Submitting Correctly

SELECT 'debug' AS component,
    :field1 AS field1,
    :field2 AS field2,
    sqlpage.request_method() AS method,
    sqlpage.post() AS all_post_data;

Component Not Rendering

Replace the component with debug:
-- Was: SELECT 'card' AS component;
SELECT 'debug' AS component;

SELECT 
    title,
    description,
    link
FROM items;

Type Mismatches

SELECT 'debug' AS component;
SELECT 
    TYPEOF(id) AS id_type,
    TYPEOF(price) AS price_type,
    TYPEOF(created_at) AS date_type,
    *
FROM products
LIMIT 1;

Tips and Tricks

Pretty Print in Browser

The debug component automatically formats JSON with:
  • Syntax highlighting
  • Proper indentation
  • Collapsible sections (in modern browsers)

Debug Multiple Queries

See results from multiple queries in sequence:
SELECT 'debug' AS component;

-- Query 1
SELECT 'Orders' AS section, COUNT(*) AS count FROM orders;

-- Query 2  
SELECT 'Users' AS section, COUNT(*) AS count FROM users;

-- Query 3
SELECT 'Products' AS section, COUNT(*) AS count FROM products;

Debug with Headers

Add context to debug output:
SELECT 'text' AS component, 
    '## Debugging User Data' AS contents_md;

SELECT 'debug' AS component;
SELECT * FROM users WHERE id = :user_id;

SELECT 'text' AS component,
    '## Debugging Order Data' AS contents_md;

SELECT 'debug' AS component;
SELECT * FROM orders WHERE user_id = :user_id;

No Parameters

The debug component accepts any parameters and displays them all. There are no specific parameter definitions - it simply shows whatever you pass to it.

Build docs developers (and LLMs) love