Skip to content

Instantly share code, notes, and snippets.

@Spindel
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spindel/2d102fd236dd554debfc to your computer and use it in GitHub Desktop.
Save Spindel/2d102fd236dd554debfc to your computer and use it in GitHub Desktop.
SQl playing
inner_query = (DBSession.query(InnerCert).filter(InnerCert.csr_id == CSR.id)
.correlate(CSR)
.order_by(InnerCert.not_after.desc())
.limit(1)
.subquery("c"))
middle_query = (DBSession.query(inner_query).select_from(CSR)
.offset(0)
.subquery("s"))
outer_query = DBSession.query(InnerCert.csr_id, InnerCert.not_after).select_from(middle_query)
SELECT (c).csr_id, (c).not_before, (c).not_after FROM (SELECT (SELECT c FROM certificate c WHERE c.csr_id=csr.id ORDER BY c.not_after DESC LIMIT 1) AS c FROM csr offset 0) s;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment