Use On Conflict Do Nothing In Postgres Like Insert Or Ignore In Other Databases
Postgres doesn't have "INSERT OR IGNORE"
Instead, use :
sql
ON CONFLICT (column_name) DO NOTHING;
For example, given this table setup :
sql
public.states (
db_id SERIAL PRIMARY KEY,
abbreviation VARCHAR(2) NOT NULL UNIQUE,
full_name VARCHAR(30)
);
public.states ENABLE ROW LEVEL SECURITY; NOT EXISTS
This INSERT statement can be run multiple times :
INSERT INTO public.states (abbreviation, full_name)
VALUES ('AL', 'Alabama')
ON CONFLICT (abbreviation) DO NOTHING;
;
The first time will insert the data. Subsequent runs will be skipped without throwing errors.