I using django framework and Postgresql develop my project. But I have a problem when many user requests at the same time. It will double inserted data when server is slow. For this reason, I will try to prevent in SQL. I want to know how to SELECT
, then INSERT
in one command.
Such as
is_created = select created_at,product from payment where created_at=current_date,product_id = '1'
if is_created == False then
insert into table (...) values (....)
CodePudding user response:
If it is from two different tables you can do like this
INSERT INTO new_table SELECT * from some_table WHERE (condition)
Check reference here
CodePudding user response:
postgreSQL supports conditionals you may find this helpful
https://www.postgresql.org/docs/current/functions-conditional.html
example
CASE expression
WHEN value THEN result
[WHEN ...]
[ELSE result]
END