Answer the question
In order to leave comments, you need to log in
How to get a list of parent IDs?
There is a comments table
comment (
id_comment integer PRIMARY KEY ,
path integer[] not null,
content text,
rating integer
)
SELECT * FROM comment ORDER BY rating DESC LIMIT
id | path | content | rating
----+---------+--------------------------------+---------
1 | {1} | я комментарий 1 | 1
2 | {1,2} | я дочь комментария 1 | 5
3 | {3} | я комментарий 3 | 3
4 | {4} | я комментарий 4 | 2
результат сортировки должен быть :
id | path | content | rating
----+---------+--------------------------------+---------
3 | {3} | я комментарий 3 | 3
4 | {4} | я комментарий 4 | 2
1 | {1} | я комментарий 1 | 1
2 | {1,2} | я дочь комментария 1 | 5
Answer the question
In order to leave comments, you need to log in
https://www.postgresql.org/docs/current/static/fun...
array_length
SELECT * FROM comment ORDER BY array_length(path, 1) ASC, rating DESC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question