SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT set_config('rgkh_journal.current_user', '1', false);
  2. WITH cte_inf_objects AS (
  3.     SELECT
  4.         o.id                AS inf_object_id,
  5.         o.mo_affiliation_id AS geo_tag_id,
  6.         cwss.name           AS cwss_name,
  7.         o.name              AS object_name,
  8.         o.type_id           AS object_type_id,
  9.         o.object_id         AS object_id
  10.     FROM pure_water.inf_object o
  11.              JOIN pure_water.cwss cwss ON cwss.id = o.cwss_affiliation_id
  12.     WHERE
  13.         o.deleted_at IS NULL
  14.       AND cwss.deleted_at IS NULL
  15. ), cte_match AS (
  16.     SELECT
  17.         pwpdo.id          AS documents_object_id,
  18.         cio.inf_object_id AS inf_object_id
  19.     FROM pure_water.pure_water_program_documents_object pwpdo
  20.              LEFT JOIN cte_inf_objects cio ON
  21.                 cio.geo_tag_id = pwpdo.geo_tag_id
  22.             AND cio.cwss_name = pwpdo.cwss_name
  23.             AND cio.object_name = pwpdo.object_name
  24.             AND cio.object_type_id = pwpdo.object_type_id
  25.             AND cio.object_id = pwpdo.object_id
  26.     WHERE pwpdo.deleted_at IS NULL
  27. )
  28. DELETE FROM pure_water.pure_water_program_documents_object WHERE id IN (
  29.     SELECT documents_object_id FROM cte_match WHERE inf_object_id IS NULL
  30. );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top