How to swing row_number in the order in which values are entered

Asked 2 years ago, Updated 2 years ago, 362 views

I would like to enter a fixed value from the program side and search the database for the value.
When I return it, I would like to return it in the order of program input.
So I'd like to use the ID in the order of values input. What should I do?

Row_number requires over.

select row_number()over(order by(x))), *from(values(2), (1), (3))asv(x);
 row_number | x
------------+---
          1 | 1
          2 | 2
          3 | 3
(3 rows)

If you do something like that, it will change depending on the price.

It's also a good idea to leave your ID on the program side.
I sometimes convert a large amount of data at once, so I prefer shorter ones so that I don't get limited query length.
Is there a good way to do it on the database side?

postgresql

2022-11-21 08:08

1 Answers

As you mentioned in the comment

select row_number()over(), *from(values(2), (1), (3))asv(x);
 row_number | x
------------+---
          1 | 2
          2 | 1
          3 | 3

I was able to go by


2022-11-21 19:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.