Skip to content

Instantly share code, notes, and snippets.

@benizar
Created March 24, 2014 13:47
Show Gist options
  • Save benizar/9740379 to your computer and use it in GitHub Desktop.
Save benizar/9740379 to your computer and use it in GitHub Desktop.
SELECT *, true AS resid FROM usos5 WHERE usos5.id_2009 IN (SELECT id_2009 FROM usos5
WHERE (xpath('//COBERTURA[@ID="EDF" and @Sup>20]/@ID', xml_2009::xml))[1]::text='EDF'
OR (xpath('//COBERTURA[@ID="UCS" and @Sup>20]/@ID', xml_2009::xml))[1]::text='UCS'
OR (xpath('//COBERTURA[@ID="UEN" and @Sup>20]/@ID', xml_2009::xml))[1]::text='UEN'
OR (xpath('//COBERTURA[@ID="UDS" and @Sup>20]/@ID', xml_2009::xml))[1]::text='UDS'
OR (xpath('//COBERTURA[@ID="TCO" and @Sup>20]/@ID', xml_2009::xml))[1]::text='TCO'
OR (xpath('//COBERTURA[@ID="TCH" and @Sup>20]/@ID', xml_2009::xml))[1]::text='TCH')
UNION
SELECT *, false AS resid FROM usos5 WHERE usos5.id_2009 NOT IN (SELECT id_2009 FROM usos5
WHERE (xpath('//COBERTURA[@ID="EDF" and @Sup>20]/@ID', xml_2009::xml))[1]::text='EDF'
OR (xpath('//COBERTURA[@ID="UCS" and @Sup>20]/@ID', xml_2009::xml))[1]::text='UCS'
OR (xpath('//COBERTURA[@ID="UEN" and @Sup>20]/@ID', xml_2009::xml))[1]::text='UEN'
OR (xpath('//COBERTURA[@ID="UDS" and @Sup>20]/@ID', xml_2009::xml))[1]::text='UDS'
OR (xpath('//COBERTURA[@ID="TCO" and @Sup>20]/@ID', xml_2009::xml))[1]::text='TCO'
OR (xpath('//COBERTURA[@ID="TCH" and @Sup>20]/@ID', xml_2009::xml))[1]::text='TCH')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment