orientjs icon indicating copy to clipboard operation
orientjs copied to clipboard

Order by generate not valid strict SQL when ordered by more attributes

Open janjilek opened this issue 8 years ago • 9 comments

Hello, When I try to order result with order('scheduleDate DESC, @rid DESC'), it generates non valid strict SQL: SELECT FROM Gift ORDER BY (scheduleDate DESC, @rid DESC) Error: com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #0: Error parsing query: SELECT FROM Gift ORDER BY (scheduleDate DESC, @rid DESC) Encountered " "," ", "" at line 1, column 45. Was expecting one of: ")" ... ")" ...

When I remove parenthesis SELECT FROM Gift ORDER BY scheduleDate DESC, @rid DESC, everything works as expected.

I am using OrientDB 2.1.8

Is there some workaround?

Thank you

janjilek avatar Apr 22 '16 10:04 janjilek

And rewrite it in raw query is not solution. I have hundreds of queries with sorting based on multiple attributes. I tested it also on 2.1.16 and same problem.

janjilek avatar Apr 22 '16 10:04 janjilek

Hi @janjilek

There is no workaround, apart from what you already found (removing the parentheses). As I wrote in another issue, parentheses in the ORDER BY condition have no meaning, this is why they are not supported.

Thanks

Luigi

luigidellaquila avatar Apr 22 '16 11:04 luigidellaquila

The problem is, that this query is generated by OrientJS query builder, so I cannot execute strict queries. And only solution is to rewrite every query without query builder => so no solution at all.

janjilek avatar Apr 22 '16 11:04 janjilek

.order('scheduleDate DESC, @rid DESC') generates (scheduleDate DESC, @rid DESC) and not scheduleDate DESC, @rid DESC

janjilek avatar Apr 22 '16 11:04 janjilek

ouch... so the problem is in OrientJS! Forwarding it to @maggiolo00 for a quick fix

Thanks

Luigi

luigidellaquila avatar Apr 22 '16 11:04 luigidellaquila

So the problem is in the driver. The solution is to remove if (utils.requiresParens(item)) { return '(' + item + ')'; } On line 809 in statement.js and return only item :-)

janjilek avatar Apr 22 '16 11:04 janjilek

Not sure, I think that method is also used by other parts of the query builder. We will check it asap

Thanks

Luigi

luigidellaquila avatar Apr 22 '16 11:04 luigidellaquila

I found workaround, use of array: .order(['scheduleDate DESC', '@rid DESC'])

janjilek avatar Apr 22 '16 12:04 janjilek

Hi, when will you release fix for this?

Thank you

janjilek avatar May 17 '16 09:05 janjilek