You can translate the question and the replies:

In view row_number() is not working expected.

In view row_number() is not working expected. but same query from VQL Shell giving me expected results. What is the issue ? I pass same where clause. From VQL shell which is need row_number 1 1 2 3 4 From View row_number 49 50 51 52 115 What causing the problem? What is the solutions?
user
21-08-2019 09:45:03 -0400
code

3 Answers

Hi, I tried executing the Row_number() function for the above scenario and its working as expected. I assume the following could have possibly happened in your case. The query you executed from VQL shell could have had the ROW_NUMBER() function and it dynamically generated the numbers starting from 1. On the other hand when a view was created using this ROW_NUMBER() function, the dynamic results are mapped as static value in the respective column of the view. So when you query the view with associated filter, this static value is returned instead of dynamically starting from 1. For example, let's say I have a view “View1” that has 10 rows, if I have a condition that return 5 rows, a VQL shell execution would give values 1 to 5 for each row of the view. * Select row_number() over (partition by 1 order by ‘1’) as row_derived from <view1> where <condition1>; Now, if I create a view “View2” out of the View1 such that the row_number() is mapped to a column say “row_derived” in View2. A query like below having the same condition would not yield the same values, this is because row_derived is a fixed column value assigned to each row of the View whereas row_number() is dynamic value generated for the resultset. * Select row_derived from <View2> where <condition1>; You can refer to the [ROW_NUMBER](https://community.denodo.com/docs/html/browse/7.0/vdp/vql/appendix/syntax_of_condition_functions/analytic_functions_window_functions#row-number) section of the Virtual DataPort Administration guide for more detailed information. Hope this helps!
Denodo Team
22-08-2019 08:30:33 -0400
code
In my case How can I avoid that static value and get dynamically starting from 1 ?
user
17-09-2019 16:16:55 -0400
Hi, For your scenario, I would first ensure the ORDER BY clause of the ROW_NUMBER () function is referencing a column value and not a constant value. Then, I would create my derived view with the same filter condition and ROW_NUMBER () function used in the VQL. For example, if “*select col1, rownumber () over (order by col1) as col2 from <view1> where <condition1>*” is my VQL (say VQL1), my derived view would be something like below: *CREATE OR REPLACE VIEW <view2> AS select col1, rownumber () over (order by col1) as col2 from <view1> where <condition1>;* In this case, a VQL (say VQL2) query *SELECT FROM <view2>* would give the same result as the one given by *VQL1*. Hope this helps!
Denodo Team
01-10-2019 06:13:59 -0400
code
You must sign in to add an answer. If you do not have an account, you can register here