darold / darold/pgFormatter

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

Open
#258 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PLpgSQL
Stars
2k
Forks
121
Avg merge
4d 21h
Merged PRs (30d)
7

Description

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 .

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the formatted SQL in the issue with the indentation problem described for subtask AS ( and the COUNT(*) AS total_sub_tasks line. Review the related discussion in issue #213 and use the shown query as the expected formatting case; done means both constructs are indented consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql
Domain
databases, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.