Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginate does not work together with PostgreSQL queries containing "DISTINCT ON" #651

Open
schuerg opened this issue Dec 6, 2021 · 1 comment

Comments

@schuerg
Copy link

schuerg commented Dec 6, 2021

Example TypeORM Query with working expected results:

// Getting all Res1 records for a user with ${username} but only for the latest series identified with `seriesId`
        const typeormQuery = getRepository(Res1)
            .createQueryBuilder('res')
            .distinctOn(['res.seriesId'])
            .where('res.username = :username', { username })
            .orderBy({
                'res.seriesId': 'DESC',
                'res.created_at': 'DESC',
            })

Running the paginate() function of this lib with this query results in the following error:

QueryFailedError: column "res.seriesId" must appear in the GROUP BY clause or be used in an aggregate function

It seems paginate constructs GROUP BY clause conflicting with DISTINCT ON

@YuriyLyukov
Copy link

Example TypeORM Query with working expected results:

// Getting all Res1 records for a user with ${username} but only for the latest series identified with `seriesId`
        const typeormQuery = getRepository(Res1)
            .createQueryBuilder('res')
            .distinctOn(['res.seriesId'])
            .where('res.username = :username', { username })
            .orderBy({
                'res.seriesId'': 'DESC',
                'res.created_at': 'DESC',
            })

Running the paginate() function of this lib with this query results in the following error:

QueryFailedError: column "res.seriesId" must appear in the GROUP BY clause or be used in an aggregate function

It seems paginate constructs GROUP BY clause conflicting with DISTINCT ON

Not sure if it will help you, but as i see, you have a redundant single quote symbol (') near "res.seriesId".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants