压缩 SQL

去掉源代码中多余的排版空白,输出仍是文本而非压缩文件。

输入: 文本结果: 文本

文本输入

案例

Compact a three-row INSERT statement

输入

INSERT INTO planets (name, moons)
VALUES ('Earth', 1),
       ('Mars', 2),
       ('Venus', 0);

Expected answer

INSERT INTO planets(name, moons) VALUES ('Earth', 1), ('Mars', 2), ('Venus', 0);
Reduce whitespace around an EXISTS subquery

输入

SELECT name
FROM customers
WHERE EXISTS (SELECT 1 FROM orders WHERE orders.customer_id = customers.id);

Expected answer

SELECT name FROM customers WHERE EXISTS(SELECT 1 FROM orders WHERE orders.customer_id = customers.id);
Keep a spaced city name inside a string literal

输入

SELECT station_id, city
FROM stations
WHERE city = 'New York'
ORDER BY station_id;

Expected answer

SELECT station_id, city FROM stations WHERE city = 'New York' ORDER BY station_id;
Compact an update with an explicit safety condition

输入

UPDATE inventory
SET stock = stock - 1
WHERE sku = 'BOOK-ALICE' AND stock > 0;

Expected answer

UPDATE inventory SET stock = stock - 1 WHERE sku = 'BOOK-ALICE' AND stock > 0;
Keep UNION ALL when combining two event streams

输入

SELECT occurred_at, 'signup' AS kind FROM signups
UNION ALL
SELECT occurred_at, 'purchase' AS kind FROM purchases;

Expected answer

SELECT occurred_at, 'signup' AS kind FROM signups UNION ALL SELECT occurred_at, 'purchase' AS kind FROM purchases;

相关工具

代码整理

操作参考

查看原始技术文档 (English)