0 votes
19 views

Structuring my query like so:

sub_query = f"""
SELECT id
    FROM nsc_dr2.object
        WHERE 't' = Q3C_RADIAL_QUERY(ra, dec, 80.89, -69.76, 5)
        AND class_star > 0.9
    LIMIT 1000
"""


query = f"""
SELECT objectid, filter, ra, dec, mag_auto, magerr_auto, mjd, exposure
    FROM nsc_dr2.meas
        WHERE objectid IN ({sub_query})
        AND filter != 'VR'
"""

works just fine for synchronous queries. However, if I try to execute as an asynchronous query, I just get "Retrieving Error." Do I need to do things differently for an async query? Thanks.

by adriansh (150 points) | 19 views

1 Answer

0 votes
Hi,

The should work now, we put a fix in, the limit in the inner query was confusing some section of the code.
Let us know if you have any problems and thank you for your contribution.

Igor
by isuarezsola (850 points)
Thank you! FYI, I found another case where something breaks when using async_=True. This works:

sub_query = f"""
SELECT id
    FROM nsc_dr2.object
        WHERE 't' = Q3C_RADIAL_QUERY(ra, dec, 80.89, -69.76, 5)
        AND class_star > 0.9
        LIMIT 1000
"""

query = f"""
SELECT objectid, mjd
    FROM nsc_dr2.meas
    WHERE objectid IN ({sub_query})
"""

But this does not:

sub_query = f"""
SELECT id
    FROM nsc_dr2.object
        WHERE 't' = Q3C_RADIAL_QUERY(ra, dec, 80.89, -69.76, 5)
        AND class_star > 0.9
        LIMIT 1000
"""

query = f"""
SELECT objectid, mjd
    FROM (SELECT *
              FROM nsc_dr2.meas
              WHERE objectid IN ({sub_query}))
"""

These are effectively the same but in the second case I nested another query where I select all the columns and then select only 2 columns with the outer SELECT. I wanted to use this format to do an INNER JOIN like so:

query = f"""
SELECT M.objectid, M.mjd, E.exptime
    FROM
    (SELECT *
        FROM nsc_dr2.meas
        WHERE objectid IN ({sub_query})) AS M
    INNER JOIN nsc_dr2.exposure AS E
        ON M.exposure = E.exposure
"""

I am still relatively new to SQL and DataLab so if this is all just user error and I am misusing the tools or writing bad queries, please let me know!

416 questions

434 answers

440 comments

636 users

Welcome to Data Lab Help Desk, where you can ask questions and receive answers from other members of the community.

Categories