Happy New Year. I’ve been trying to write a notebook to grab cutout of an asteroid in DP1 and a corresponding image of the sky in a different filter when the asteroid has moved. I think I’ve ogttne that notebook to work, but I find that I get different images returned back when I run the notebook more than once (even if I clear the kernel and all output). It looks like maybe the queries don’t always return back in the same order. See the screen recording here and the notebook I’m running can be found here. Any help or guidance would be much appreciated. Thanks
Hi Meg-
Queries are not guaranteed to always return results in the same order. If you would like to ensure that they do, you can do either of the following:
-
Include “ORDER BY” in the query to sort the results before selecting the first one (you can sort by whichever column you like – I chose
visithere):
query = f"SELECT * from dp1.DiaSource where ssObjectId={result_df.ssObjectId[3]} ORDER BY visit limit 1" -
Return query results as a dataframe without using “limit 1” (i.e., return all results), then sort the dataframe before selecting an element.
It is generally true that the same query will not necessarily return results in the same order, so if you want to ensure that your results are repeatable, you need to do some sorting (or a more tightly specified query).
Thanks @jeffcarlin . That’s what I thought, but it surprised a few people when I mentioned that the same query return results in different order when run a second time (or rather oscillates between two orders).
Ideally I’d want to explicitly randomize the list and limit to 1 in this case to create an example for an undergraduate student, but there’s no random function implemented in the ADQL on the science platform.