-
-
Notifications
You must be signed in to change notification settings - Fork 591
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
PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list #990
Comments
Did you find the solution? |
Does anyone have a reproducible test case that we can add to the specs? |
I don´t have specs, but I will try explain. I have a repository method for return promotions paginated and ordered for a logical field(qtdViews) public async viewsOrdenation(
{ order_by, logged_user_id },
{ page, skip, take }: SearchParams,
): Promise<IPaginatorPromotion> {
const promotions = await this.ormRepository
.createQueryBuilder('promotions')
.loadRelationCountAndMap('promotions.qtdComments', 'promotions.comments')
.loadRelationCountAndMap('promotions.qtdViews', 'promotions.views')
.loadRelationCountAndMap(
'promotions.qtdLikes',
'promotions.likes',
'il',
qb => qb.where('il.is_liked = :is_liked', { is_liked: true }),
)
.loadRelationCountAndMap(
'promotions.is_liked',
'promotions.likes',
'iL',
qb =>
qb
.where('iL.profile_id = :profile_id', {
profile_id: logged_user_id,
})
.andWhere('iL.is_liked = :is_liked', { is_liked: true }),
)
.leftJoinAndSelect('promotions.advertiser', 'advertiser')
.leftJoin('advertiser.profile', 'profile')
.addSelect([
'profile.id',
'profile.name',
'profile.email',
'profile.cellphone',
'profile.avatar',
])
.leftJoin('promotions.views', 'views')
.addSelect('COUNT(views.id) as qtdViews')
.where('promotions.is_expired = :is_expired', { is_expired: false })
.orderBy('qtdViews', 'DESC')
.groupBy('promotions.id, profile.id, advertiser.id')
.skip(skip)
.take(take)
.getMany();
const count = await this.ormRepository
.createQueryBuilder('promotions')
.where('promotions.is_expired = :is_expired', { is_expired: false })
.getCount();
const data = {
per_page: take,
total: count,
cuurent_page: page,
data: promotions,
};
return data;
}
return data;
} But when the route it´s called return the error: "QueryFailedError: for SELECT DISTINCT, ORDER BY expressions must appear in select list" Can you help me, please? |
@brunnossanttos that's all TypeScript code you posted above, so I'm not quite sure how that relates to this issue 😄 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
won't this conflict with the main table's |
Rails v6.0.4.6
Ruby v2.5.3
Issue
This statement is invalid with
SELECT DISTINCT
clause:Solution
Add
friendly_id_slugs.id
to select statement:The text was updated successfully, but these errors were encountered: