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.
Code
-- 无 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
SQL DDL to TypeScript ConverterConvert SQL CREATE TABLE DDL statements into strict TypeScript interfaces with nullable, array, enum, JSONB, and Date or ISO string column mappings.PostgreSQL EXPLAIN AnalyzerAnalyze PostgreSQL EXPLAIN ANALYZE text or FORMAT JSON plans locally to flag Seq Scans, slow nodes, row misestimates, disk sorts, and index hints.Multi-Mode Escape & Unescape CodecEscape and unescape strings safely across JSON, JavaScript, SQL single-quoted literals, POSIX shell single quotes, and RFC 4180 CSV cells in your browser.SQL FormatterReformat SQL by uppercasing reserved words and breaking lines before SELECT, FROM, WHERE, and other clauses.
Report a problem with this exampleOpens a pre-filled issue on GitHub.