SELECT Without FROM Constant Rows

A FROM-less SELECT evaluates one row of constant expressions, the quickest way to probe function output, casts, and operator semantics.

SqlData Fetching

Code

snippet
-- 无 FROM 的 SELECT 是一行常量表达式:探测函数输出与运算符语义的最短路径
SELECT
    2 + 2                          AS four,
    'a' || 'b'                     AS concat,
    17 / 5                         AS int_div,        -- 3:整数除法截断
    17.0 / 5                       AS numeric_div,    -- 3.4
    now() > timestamp '2000-01-01' AS clock_running;

-- FROM (VALUES ...) 把一行常量扩展成多行临时数据
SELECT k, v
FROM (VALUES
    ('host', 'db.internal'),
    ('port', '5432')
) AS cfg(k, v)
ORDER BY k;

-- 函数调用与类型转换同样可以无表直接验证
SELECT gen_random_uuid() IS NOT NULL AS uuid_ok,
       length(md5('x'))              AS md5_len,
       interval '1 day' * 3          AS three_days;

Inside the snippet

SELECT statements share the script.

Breaking the statements into their working parts: an ORDER BY that fixes the output order; NOT NULL qualifiers on the required columns.

Core lines

SELECT
    2 + 2                          AS four,
    'a' || 'b'                     AS concat,
    17 / 5                         AS int_div,        -- 3:整数除法截断
    17.0 / 5                       AS numeric_div,    -- 3.4
    now() > timestamp '2000-01-01' AS clock_running;
SELECT gen_random_uuid() IS NOT NULL AS uuid_ok,
       length(md5('x'))              AS md5_len,
       interval '1 day' * 3          AS three_days;
SELECT k, v
FROM (VALUES
    ('host', 'db.internal'),
    ('port', '5432')
) AS cfg(k, v)
ORDER BY k;

Interactive Tools for This Topic