Hey, I am trying to do a raw query but it does not...
# orm-help
j
Hey, I am trying to do a raw query but it does not seem to work. If I run this:
Copy code
const amountMale = await this._prismaService.$queryRaw`
	SELECT 
		COUNT(profile) as count
	FROM "public"."User" AS user, "public"."Profile" AS profile
	WHERE user.profileId = profile.id
	WHERE profile.gender = MALE
`
I get the following error:
Copy code
Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near "user"`
It is solved by removing the
AS user
and
AS profile
parts, but then it gives an error on
WHERE User.profileId = Profile.id
saying the
.
is an invalid character. Is there any way to solve this? Prisma version is 3.13, using Postgresql
1
r
try put the table name in
"
:
Copy code
WHERE "User".profileId = "Profile".id
n
Can you also try wrapping the column name with the quotes
"
?
Copy code
const amountMale = await this._prismaService.$queryRaw`
	SELECT 
		COUNT(profile) as count
	FROM "public"."User" AS user, "public"."Profile" AS profile
	WHERE "user"."profileId" = profile.id
	WHERE "profile"."gender" = MALE
j
I solved it by using
u
as name instead of
user
, I think it might have been related to that? But not sure