darold / pgFormatter

A PostgreSQL SQL syntax beautifier that can work as a console program or as a CGI. On-line demo site at http://sqlformat.darold.net/
PostgreSQL License
1.68k stars 101 forks source link

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

Open ray-x opened 3 years ago

ray-x commented 3 years ago

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 .

darold commented 3 years ago

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.

jacek0x commented 2 years ago

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?