dr-rodriguez / AstrodbWeb

A web application for accessing the BDNYC SQL database
MIT License
0 stars 2 forks source link

Use Subqueries in Browse #25

Open dr-rodriguez opened 7 years ago

dr-rodriguez commented 7 years ago

Some python code with pandas is used to group and count up photometry/spectroscopy for each object when using the Browse feature. It may be simpler to use SQL Subqueries in this case. Don't know if it would be (significantly?) faster, but it's something to look into.

dr-rodriguez commented 7 years ago

Need to test it, but something like this might work:

SELECT s.id, s.ra, s.dec, s.shortname, s.names, s.comments, 
    (SELECT COUNT(*) FROM photometry AS p WHERE s.id = p.source_id) AS phot_counts, 
    (SELECT COUNT(*) FROM spectra AS sp WHERE s.id = sp.source_id) AS spec_counts
FROM sources AS s
dr-rodriguez commented 7 years ago

That code works, but have to ensure to set use_converters=False as the _explicit_query() method will otherwise break it.