Answer the question
In order to leave comments, you need to log in
INSERT without duplicates in PostgreSQL?
Good afternoon, there is a table:
Query example:
UPDATE users_data ud
SET
count = (ud.count + 1),
updated_at = now()
WHERE
user_id = :uid AND
command = :command AND
created_at::date = :now;
INSERT INTO users_data (user_id, command)
SELECT :uid, :command
WHERE NOT EXISTS (
SELECT 1
FROM users_data
WHERE
user_id = :uid AND
command = :command AND
created_at::date = :now
LIMIT 1
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question