Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. WITH stk as (SELECT stk.id, stk.rowid, stk.updateid, stk.source, stk.userid, stk.writetime, stk.deleted, stk.readgroups, stk.writegroups, stk.classification, stk.strikeidentifier, stk.strikedate, stk.operation, stk.roe, stk.misrep, stk.isqc, ord.id ordid, ord.rowid ordrowid, ord.updateid ordupdateid, ord.source ordsource, ord.userid orduserid, ord.writetime ordwritetime, ord.deleted orddeleted, ord.readgroups ordreadgroups, ord.writegroups ordwritegroups, ord.classification ordclassification, ord.strikeid ordstrikeid, ord.splashdtg ordsplashdtg, ord.secondaryexplosions ordsecondaryexplosions, ord.cda ordcda, ord.observer ordobserver, ord.mea ordmea, ord.striketype ordstriketype, ord.engageunit ordengageunit, ord.aircraft ordaircraft, ord.callsign ordcallsign, ord.acbase ordacbase, ord.nationality ordnationality, ord.ato ordato, ord.country ordcountry, ord.province ordprovince, ord.city ordcity, ord.locationgeo ordlocationgeo, ord.geom ordgeom FROM strikelog.strike stk LEFT JOIN strikelog.ordnance ord ON stk.id = ord.strikeid WHERE stk.updateid IS NULL AND NOT stk.deleted AND NOT stk.DELETED ), ord as (SELECT stk.ordid id, stk.ordrowid rowid, stk.ordupdateid updateid, stk.ordsource source, stk.orduserid userid, stk.ordwritetime writetime, stk.orddeleted deleted, stk.ordreadgroups readgroups, stk.ordwritegroups writegroups, stk.ordclassification classification, stk.ordstrikeid strikeid, stk.ordsplashdtg splashdtg, stk.ordsecondaryexplosions secondaryexplosions, stk.ordcda cda, stk.ordobserver observer, stk.ordmea mea, stk.ordstriketype striketype, stk.ordengageunit engageunit, stk.ordaircraft aircraft, stk.ordcallsign callsign, stk.ordacbase acbase, stk.ordnationality nationality, stk.ordato ato, stk.ordcountry country, stk.ordprovince province, stk.ordcity city, stk.ordlocationgeo locationgeo, stk.ordgeom geom, COALESCE(NULLIF(json_agg(tgt)::TEXT, '[null]'), '[]')::JSONB as targets FROM stk LEFT JOIN strikelog.target tgt ON stk.ordid = tgt.ordnanceID WHERE stk.ordupdateid IS NULL AND NOT stk.orddeleted GROUP BY stk.ordid, stk.ordrowid, stk.ordupdateid, stk.ordsource, stk.orduserid, stk.ordwritetime, stk.orddeleted, stk.ordreadgroups, stk.ordwritegroups, stk.ordclassification, stk.ordstrikeid, stk.ordsplashdtg, stk.ordsecondaryexplosions, stk.ordcda, stk.ordobserver, stk.ordmea, stk.ordstriketype, stk.ordengageunit, stk.ordaircraft, stk.ordcallsign, stk.ordacbase, stk.ordnationality, stk.ordato, stk.ordcountry, stk.ordprovince, stk.ordcity, stk.ordlocationgeo, stk.ordgeom) SELECT to_jsonb(rows) FROM (SELECT stk.id, stk.rowid, stk.updateid, stk.source, stk.userid, stk.writetime, stk.deleted, stk.readgroups, stk.writegroups, stk.classification, stk.strikeidentifier, stk.strikedate, stk.operation, stk.roe, stk.misrep, stk.isqc, COALESCE(NULLIF(json_agg(ord)::TEXT, '[null]'),'[]')::JSONB as ordnances FROM stk LEFT JOIN ord ON stk .ordid = ord.id GROUP BY stk.id, stk.rowid, stk.updateid, stk.source, stk.userid, stk.writetime, stk.deleted, stk.readgroups, stk.writegroups, stk.classification, stk.strikeidentifier, stk.strikedate, stk.operation, stk.roe, stk.misrep, stk.isqc) rows;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement