pgFormatter icon indicating copy to clipboard operation
pgFormatter copied to clipboard

Indenting issue with subqueries and UNION ALL

Open darkixion opened this issue 3 years ago • 0 comments

I'm not sure what is throwing the formatter off, but I get a mis-formatted output with the following query:

SELECT
    a.b AS "B",
    a.c AS "C"
FROM
    a
WHERE
    d IN (
        SELECT
            e
        FROM (
            SELECT
                f FF
            FROM
                h HH) i
        UNION ALL
        SELECT
            j
        FROM
            l LL
        WHERE
            h.o IS NULL)
ORDER BY
    DECODE(p, 'a', SYSDATE, 'b', SYSDATE, 'c', SYSDATE, d) ASC,
    NVL (q, 1) ASC,
    CASE WHEN r = 0
        AND s != 'N' THEN
        a.y
    ELSE
        a.z
    END ASC;

I end up with the following output. Take note of the ORDER BY section:

SELECT
    a.b AS "B",
    a.c AS "C"
FROM
    a
WHERE
    d IN (
        SELECT
            e
        FROM (
            SELECT
                f FF
            FROM
                h HH) i
        UNION ALL
        SELECT
            j
        FROM
            l LL
        WHERE
            h.o IS NULL)
ORDER BY
    DECODE(p, 'a', SYSDATE, 'b', SYSDATE, 'c', SYSDATE, d) ASC,
NVL (q, 1) ASC,
CASE WHEN r = 0
    AND s != 'N' THEN
    a.y
ELSE
    a.z
END ASC;

darkixion avatar Aug 18 '22 14:08 darkixion