Skip to Content

row_number with out order by in hana

Hi,

I have a calculation view which exports my products in a specific order. I want to retain the order of products. But when i expose it as a OData service , the products are sorted by product key. While it is built in feature / Bug of OData that it sorts the records by key if no order by is mentioned , i want to add an extra column in my view to retain the order . For that , I thought of storing the row number for each row. I dont have any columns which i have to mention iin order by clause. I could not use row_number function without order by clause in hana. When i write below statement,

select

PRERULE, POSTRULE , row_number() over(order by (SELECT 1)) as rownum from "PAL"."AP_RULES_P" WHERE "PRERULE" = '73'

I got an error saying

incorrect syntax near ")": line 1 col 66 (at pos 66)

Can some one help me how to fix the situation?

Cant we use row_number with out order by in hana?

regards,
Deepthi lakshmi.A

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Jul 30, 2013 at 10:02 PM

    Hello Deepthi,

    Have you tried the following code instead of SELECT 1 ... do

    SELECT 1 FROM DUMMY

    Regards, Werner

    Werner Steyn

    Platinum Product Expert - Database and Technology (D&T) | SAP HANA

    Customer Solution Adoption (CSA) | Technology and Innovation Platform (TIP)

    Add a comment
    10|10000 characters needed characters exceeded

    • It's possible to use ROW_NUMBER() OVER().

      But since this really only adds an increasing number to every line of the result set, there is no guarantee that the same line will receive the same number when the statement is executed again.

      It's another variant of "without ORDER BY no sorting must be assumed".

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.