| От | LaMi |
|---|---|
| Тема | Re: How ad an increasing index to a query result? |
| Дата | |
| Msg-id | 4AD9BF7C.5000706@datalogiq.net обсуждение исходный текст |
| Ответ на | How ad an increasing index to a query result? (Josip <josip.2000@gmail.com>) |
| Список | pgsql-general |
Josip wrote:
> Hello,
>
> Could somebody please try to help me with this problem?
> So, let’s say that I have the query:
>
> CREATE SEQUENCE c START 1;
>
> SELECT a, nextval('c') as b
> FROM table1
> ORDER BY a DESC LIMIT 5;
>
> I.e., I want to pick the 5 largest entries from table1 and show them
> alongside a new index column that tells the position of the entry. For
> example:
>
> a | b
> --------
> 82 | 5
> 79 | 4
> 34 | 3
> 12 | 2
> 11 | 1
>
> However, when I try this approach, the values of column b don’t follow
> the correct order. How should I go about and modify my code?
>
You can try using a sequence with a negative increment like below
CREATE SEQUENCE test_sequence
INCREMENT -1
START 100
MINVALUE 1
MAXVALUE 100;
- mrLami
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера