Skip to content

order clause not parsed correctly from subquery #413

Description

@muratonnet

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions