0 votes
135 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 (170 points) | 135 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 (890 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!

449 questions

463 answers

473 comments

658 users

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

Categories