Z
Z
Zuoya2021-01-14 09:57:30
PostgreSQL
Zuoya, 2021-01-14 09:57:30

How to sort list by time using id in Postgresql?

+ another question, is it possible to do insert and update in one query?
for example, to make an insert into the table if there is no such key. while I do this. insert, if there is no error, then you can update. Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zuoya, 2021-01-14
@Zuoya

Sorting solved using subqueries.
SELECT * FROM post WHERE date >(SELECT datepst FROM post WHERE id =$1) ORDER BY date
ASC In such a case, using transactions worked.

D
Dr. Bacon, 2021-01-14
@bacon

1. order by id
2. ON CONFLICT ... DO UPDATE for INSERT

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question