I've got two columns in PostgreSQL, hostname and ip. Hostname is the primary key and ip is an array of IPs. I want to be able to insert IPs for a give hostname, on conflict I want to append to the array with the data I'm trying to insert and the output data should be unique.
e.g
hostname - ip
test.com {1.1.1.1,2.2.2.2}
Input
I attempt to insert...
test.com {1.1.1.1, 3.3.3.3, 4.4.4.4}
Output
test.com {1.1.1.1, 2.2.2.2 ,3.3.3.3, 4.4.4.4}
insert into auto_scope_pre_proc (hostname,ip) values ('test.com', '{10.10.10.10, 10.10.10.22}'::inet[])
on conflict (hostname) do update
SET ip = array_append(auto_scope_pre_proc.ip,ip);