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

order clause not parsed correctly from subquery #413

Open
muratonnet opened this issue Jan 14, 2020 · 0 comments
Open

order clause not parsed correctly from subquery #413

muratonnet opened this issue Jan 14, 2020 · 0 comments

Comments

@muratonnet
Copy link

I have a query in postgresql like below

select * from
	(
		select 
			field_feedback_action_id, 
			count(1) as field_feedback_action_count
		from t_field_feedback
		group by field_feedback_action_id
	) t
where t.field_feedback_action_count > 1
order by t.field_feedback_action_count desc
limit 4

i try to create this sql like below

let subQuery = table
	.subQuery('t')
	.select(
		table.field_feedback_action_id,
		table.field_feedback_action_id.count().as("field_feedback_action_count")
	)
	.group(table.field_feedback_action_id);

let query = table.
	from(subQuery)
	.where(subQuery.field_feedback_action_count.gt(1))
	.order(subQuery.field_feedback_action_count.descending)
	.limit(4)

bu it is converted to

	SELECT * FROM (
		SELECT 
			"t_field_feedback"."field_feedback_action_id",
			COUNT("t_field_feedback"."field_feedback_action_id") AS "field_feedback_action_count" 
		FROM "t_field_feedback" 
		GROUP BY "t_field_feedback"."field_feedback_action_id"
	) "t" 
	WHERE ("t"."field_feedback_action_count" > 1) 
	ORDER BY "t_field_feedback"."field_feedback_action_id" 
	DESC LIMIT 4

subQuery.field_feedback_action_count.gt(1).toString()
is converted to
"t"."field_feedback_action_count" > 1

but

subQuery.field_feedback_action_count.descending
is converted to
COUNT("t_field_feedback"."field_feedback_action_id") DESC

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

1 participant