0

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 (....)
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
devnext
  • 872
  • 1
  • 10
  • 25
  • You could be looking at this similar solution [here](https://stackoverflow.com/questions/16636698/do-conditional-insert-with-sql). – Edper Jun 11 '22 at 06:13

1 Answers1

0

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 
  • thank you for awnser. but i cannot use INSERT INTO after THEN. " syntax error at or near "INTO"" – devnext Jun 11 '22 at 04:41