PostgreSQL Finding IDs that don't exist in two other tables -
i want change io_dl
field 1 0 in io
table, if 3 conditions hold true
io
table pkey -> io_id
- the pkey
io
not in entire tablem
fkey namedm_id
- the pkey
io
not contained in tablep
, columnp_id
csv delimited string of ids ex. "1923,2309,210" - the current value
io_dl
field inio
table set 1
step 3 guess isn't needed setting 0 0 doesn't mess up, check may slow query down?
this i've tried , im getting massive list of same io_id
s listed, think i'm using join or union wrongly.
update io set io_dl = 0 io_id in ( select i.io_id io inner join ( select p_id "io_id" p union select regexp_split_to_table(m.m_id, ',')::integer id m ) q on i.io_id != q.io_id i.io_dl = 1 );
made own solution few minutes later simpler query believe.
update io set io_dl = 0 io_id in ( select i.io_id io i.io_id not in ( select p_id "io_id" p union select regexp_split_to_table(m.m_id, ',')::integer "io_id" m ) , i.io_dl = 1 );
use except
distinct ids
:
update io set io_dl = 0 io_id in ( select io_id io except ( select p_id p union select regexp_split_to_table(m_id, ',')::integer m ) ) , io_dl = 1 returning *;
by adding returning *
can control how many rows updated.