[ad_1]
I need a little help understanding this issue. I have a few replies sorted by date. Here is my table
CREATE TABLE topic_replies (
reply_id BIGSERIAL PRIMARY KEY NOT NULL,
author VARCHAR(30) REFERENCES users(username) ON DELETE CASCADE NOT NULL,
quote_body TEXT,
body TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
topic_id BIGINT REFERENCES forum_topics(topic_id) ON DELETE CASCADE NOT NULL
)
When I’m querying data looks ordered but when I perform an update for a specific record data gets changed and the record updated is last in the list now.
SELECT topic_replies.*, users.avatar as author_avatar, users.user_id as author_id,
users.role as author_role, users.name as author_name FROM topic_replies
LEFT JOIN users ON users.username = topic_replies.author
WHERE topic_id = $1
ORDER BY topic_replies.created_at DESC;
This is my query for updating the reply
UPDATE topic_replies
SET
body = $1
WHERE
reply_id = $2
RETURNING *;
Keep in mind that when I’m updating the reply, created_at
row is not getting changed so why the order is messed up?
initial order before updating
reply_id | created_at
------------+-----------------
1 | 2020-01-10
**2 | 2020-01-11**
3 | 2020-01-12
4 | 2020-01-13
(4 rows)
order after updating record 2
reply_id | created_at
------------+-----------------
1 | 2020-01-10
3 | 2020-01-12
4 | 2020-01-13
**2 | 2020-01-11**
(4 rows)
Thank you!
[ad_2]