pgFormatter icon indicating copy to clipboard operation
pgFormatter copied to clipboard

Bad indentation for CTE and `Count(*) AS` in return query statement

Open ray-x opened this issue 4 years ago • 2 comments

Here is the code been formatted

CREATE FUNCTION get_jobs (orgId varchar, pagesize integer, pagenum integer)
    RETURNS TABLE (
        job_id varchar)
    LANGUAGE plpgsql
    AS $$
BEGIN
    RETURN QUERY WITH filtered_jobs AS (
        SELECT
            j.id AS job_id
        FROM
            jobs j
        ORDER BY
            j.created_at DESC
        LIMIT pageSize OFFSET pageSize * (pageNum - 1)
),
subtask AS (
    SELECT
        fj.job_id
    FROM
        filtered_jobs fj
),
counts AS (
    SELECT
        ss.job_id,
        COUNT(*) AS num,
    COUNT(*) AS total_sub_tasks
FROM
    subtask ss
)
SELECT
    j.job_id
FROM
    filtered_jobs j
END;
$$;

One issue is subtask AS ( is not properly indentened. Similar to #213 The other issue is COUNT(*) AS total_sub_tasks .

ray-x avatar Aug 28 '21 04:08 ray-x

Yes there is a major formatting issue with CTE, I'm still missing time to work on it but it is in my todo list.

darold avatar Sep 28 '21 04:09 darold

Yes there is a major formatting issue with CTE, I'm still missing time to work on it but it is in my todo list.

Any updates on this?

jacek0x avatar May 20 '22 13:05 jacek0x