Reputation: 161
I am writing a stored procedure to update target table from a source table. The data comes in daily and will have data for the last 7 days as well. I would like to only insert new data in to target table after comparing the source and target tables based on the Date column.
Not sure how to write this in BQ
if source.date = target.date
then dont insert
else
insert
Upvotes: 0
Views: 805
Reputation: 1270401
Presumably, you assume that you have data from a given date or no data If that is the case, the logic you want is:
insert into target ( . . . ) -- list the columns
select . . . -- list the columns
from source s
where not exists (select 1 from target t where t.date = s.date);
Upvotes: 1
Reputation: 24603
one way is (pseudo code) :
insert into target
select * from source
where source.date <> target.date
Upvotes: 1