user2139745
user2139745

Reputation: 1811

postgres - load from sql file (skip errors), leave existing ones and create non existing

I have an sql file(we can generate this in whatever way we want).

I want to load it fully initially, then want to update(delete, create) db based using logic.

Later, if I want to delete more, we can simply delete.
But, if we want to add more, then we need to import sql again. Before importing, I cant drop those tables because they are already foreign keys to others. So, I can only do this:
Run sql file somehow to add only non-available entries to database skipping available entries so I can skip errors ( duplicate key value violates unique ).

Upvotes: 0

Views: 171

Answers (1)

Tometzky
Tometzky

Reputation: 23890

Import your data to a temporary table and then just use something like:

insert into real_table_name
select * from temporary_table_name
where id not in (select id from real_table_name);

Upvotes: 1

Related Questions