﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33309	DISTINCT ON fails with mixed-case field aliases	Christophe Thiery	Arsalan Ghassemi	"If you pass an aliased field name to distinct(), it will fail if the alias has some capital letters.
{{{
from django.contrib.auth.models import User
from django.db.models import F

User.objects.annotate(the_alias=F('first_name')).values('the_alias', 'id').order_by('the_alias', 'id').distinct('the_alias')
# Works

User.objects.annotate(theAlias=F('first_name')).values('theAlias', 'id').order_by('theAlias', 'id').distinct('theAlias')
# Fails with:
# ProgrammingError: column ""thealias"" does not exist
# LINE 1: SELECT DISTINCT ON (theAlias) ""auth_user"".""id"", ""auth_user"".""first_name"" AS ""theAlias""...
}}}
It looks like the DISTINCT ON clause in the generated SQL is missing double quotes.

Tested on Django 3.2.9 and postgres 12.8."	Bug	closed	Database layer (models, ORM)	3.2	Normal	fixed		Ad Timmering Egor R	Ready for checkin	1	0	0	0	0	0
