Home > Software engineering >  How to change the query so that it checks if the table is not empty
How to change the query so that it checks if the table is not empty

Time:03-01

I've got a query:

INSERT INTO rates (name, value, time) 
SELECT name, value, time
FROM updated_rates
ON CONFLICT (name) DO UPDATE
SET value = excluded.value, time = excluded.time;
TRUNCATE updated_rates;

How to change the query so that it does the actions above if updated_rates is not empty

CodePudding user response:

You can use exists:

exists (select * from updated_rates)

But if it's empty it will simply not insert anything.

  • Related