Query Gaia by star name - astronomy

I am attempting to query Gaia programmatically in python to get the parallax, distance and kmag of specific stars. I can write a query which obtains the parallax, but only for all stars, not a set of stars or one specific star. Ideally I would just be able to pass the query function a star name but I can't figure out from the documentation how to do this (or even how to make the star name, rather than just the Gaia source_id, a column in the returned table).
My current script is as follows:
query = """SELECT source_id, ra, dec, parallax FROM gaiadr2.gaia_source """
job = Gaia.launch_job(query)
results = job.get_results()
Any pointers are much appreciated!

so what you want is a cone search, so I would go into Stellarium and get the RA and dec coords, then convert it using this website: https://www.swift.psu.edu/secure/toop/convert.htm, input the data, and the last digit is your FOV. (in Stellarium) then submit SQL query BUT go back and edit it, so from here you can add all your code like so:
SELECT parallax, distance, kmag, ra
FROM gaiadr2.gaia_source
WHERE 1 = CONTAINS(POINT('ICRS', ra, dec),
CIRCLE('ICRS', 274.2667(RA), -18.5975(DEC), 1.87(FOV)))
enter image description here

Related

Can Access queries match one value in a table with the field name in the other table?

CPC is a kind of measurement, we ran different CPCs in every day and get second data. So I have a long list of CPC files and one location file. In here, I only use CPC1 in 4/27/2017 as an example (the following first jpg). Location file has the longitude and latitude of CPCs everyday of the entire experiment (the second example table in the following jpg).
Because the location only has date, ID, and long/lat, I want to link ID (CPC name) column in location file to file name (also CPC name) of every CPC files.
I am not sure how it can be done, but I guess it should be done in SQL or VBA. I hope there is a simpler way. Although I only know VBA in Excel, but if it has to be done in SQL or VBA, please get me some ideas. Thank you so much.
Example of CPC1
Example of location file
Perhaps this query will accomplish:
SELECT location.*, CPC1.* FROM CPC1 INNER JOIN CPC1.Date ON location.date WHERE location.ID = "CPC1";
Assumes same dates are in both tables, hence the INNER JOIN.

MySQL - get the rest of string from found one

I have an problem, i am using simple query to select from column (VARCHAR), what user searched and appending +1 string to it from database.
For example if i had in table following values (title):
My name is SOMEONE.
Have a great day.
It's possible.
Mouse on the way.
My mouse is on other way.
Is there any mouse?
And user wants to retreive the keyword mouse.
I wish to output him following from the values above:
Mouse on
mouse is
mouse?
Also if the user types Mouse on it should return
Mouse on the and so on, appending one string from database to found ones (if any).
I could do it outside of database, but i need after retreiving string DISTINCT values with Limitation.
For now i used SUBSTRING_INDEX(title , ' ', ".$totalWords.")
where $totalWords were the user sent to my programme.
Problem with my query was when you type other it will find and return:
My mouse but that's not what i want, i want to it output from found string +1 append so it would be other way
If i wasn't so clear i will give my best to explain it better.
Thank you.
You could use LOCATE(substr,str) 1 to locate the position of the first occurence of the user input. afterwards use SUBSTRING(str FROM pos) 2 to get a substring starting at the position of the first occurence of the user input and finally use your SUBSTRING_INDEX(title , ' ', ".$totalWords.") to get the second word.
PS: Sounds like an autocompletion feature? probably there are better ways to do it than with a relational database

How to find last item in a repeated structure in bigquery

I have a nested repeated structure, the repeated structure is of variable length. For example, it could be a person object with a repeated structure that holds cities the person has lived in. I'd like to find the last item in that list say to find current city person lives in. Is there an easy way to do this, I tried looking around jsonpath functions but I'm not sure how to use it with "within". Any help please?
1) You can use LAST and WITHIN
SELECT
FIRST(cell.value) within record ,
LAST(cell.value) within record
FROM [publicdata:samples.trigrams]
where ngram = "! ! That"
2) or if you want something more advanced you can use POSITION
POSITION(field) - Returns the one-based, sequential position of field within a set of repeated fields.
You can check the samples from trigrams (click on Details to see the unflatten schema)
https://bigquery.cloud.google.com/table/publicdata:samples.trigrams?pli=1
And when you run POSITION, you get the ordering of that field.
SELECT
ngram,
cell.value,
position(cell.volume_count) as pos,
FROM [publicdata:samples.trigrams]
where ngram = "! ! That"
Now that you have the position, you can query for last one.

Multiple databases, possibly creating a loop?

I have the following code below...the query works, but I'm looking for a better way to search though an entire column for a specific criteria. I think my question is going to require a loop, I'm just not sure how to perform it.
The last line of code states '
Where [dbIdwWhseLC].[dbo].[tbItemTxt].[sTxt] like '%258912.pdf
The value 258912.pdf is the value in
[IDEAUrlBot].[dbo].[IDEA Project Tracker].[Filename]
I would like to try and create a method where the query reads one value in sTxt, then compares the whole column to Filename. If it finds the value, then display sTxt, if not, go to the next value in sTxt and begin searching each value in Filename.
Please let me know if you need additional information. Thanks in advance.
Select [dbIdwWhseLC].[dbo].[tbItemTxt].[nItemId]
, [sTxtType]
, [IDEAUrlBot].[dbo].[tbl_IDWItems].[nUrlId]
, [IDEAUrlBot].[dbo].[tbl_Urls].[sUrl]
, [sTxt]
, [Filename]
, [dbIdwWhseLC].[dbo].[tbItemTxt].[vUpdateDt]
From [dbIdwWhseLC].[dbo].[tbItemTxt]
Left Join [IDEAUrlBot].[dbo].[tbl_IDWItems] on [dbIdwWhseLC].[dbo].[tbItemTxt].[nItemid] = [IDEAUrlBot].[dbo].[tbl_IDWItems].[nItemid]
Join [IDEAUrlBot].[dbo].[tbl_Urls] on [IDEAUrlBot].[dbo].[tbl_IDWItems].[nUrlId] = [IDEAUrlBot].[dbo].[tbl_Urls].[nUrlId]
Join [IDEAUrlBot].[dbo].[IDEA Project Tracker] on [IDEAUrlBot].[dbo].[tbl_IDWItems].[nUrlId] = [IDEAUrlBot].[dbo].[IDEA Project Tracker].[UrlId]
Where [dbIdwWhseLC].[dbo].[tbItemTxt].[sTxt] like '%258912.pdf'
If I understand you correctly, it ought to be possible to do this:
select itemTxt.[nItemId]
, [sTxtType]
, idwItems.[nUrlId]
, urls.[sUrl]
, [sTxt]
, [Filename]
, itemTxt.[vUpdateDt]
From [dbIdwWhseLC].[dbo].[tbItemTxt] as itemTxt
Left Join [IDEAUrlBot].[dbo].[tbl_IDWItems] as idwItems
on itemTxt.[nItemid] = idwitems.[nItemid]
Join [IDEAUrlBot].[dbo].[tbl_Urls] as urls
on idwItems.[nUrlId] = urls.[nUrlId]
Join [IDEAUrlBot].[dbo].[IDEA Project Tracker] projTracker
on itemText.[nUrlId] = projTracker.[UrlId]
Where itemTxt.[sTxt] like '%258912.pdf' -- not sure you intend this to remain
and projTracker.[FileName] = itemTxt.[sTxt]
But that's so simple that there must be some aspect to what you're looking for that's not clear to me.
Do you want to stop searching after you find a match between [FileName] and [sTxt]? If you want to return exactly one record, you can just change the first line to
select top 1 itemTxt.[nItemId]
... and add an ORDER BY clause to the end to control how the results are sorted and therefore which one is the "top 1".
Do you need to use wildcards when matching [FileName] and [sTxt]? It's not clear to me from the description which column would have the full path (or file name) and which would have just "258912.pdf", but you could change my last line to:
itemTxt.[sTxt] like ('%' + projTracker.[FileName])
If you need something more complex, like the first record from itemTxt.[sTxt] that matches projTracker.[FileName] for every record in projTracker, please say so in the comments.
If none of this is along the lines of what you need, you'll need to elaborate on what it is you do need. Please add more detail to your question, such as an example of what the output should look like or what you plan to do with it.

PHP/MySQL - Changing Query on clicking a link

I have a very basic site (just learning this stuff) where I have the results for a hockey pool I do from here.
I want to build a page that lists the players and then when they click on a name, a page comes up with just that player's picks on it. You can see the kind of page I mean here.
THis page currently only shows one player, as I am using this query:
$q = "SELECT *, player_id, handle
FROM round_one
INNER JOIN players USING (player_id)
WHERE (player_id = 1)";
Right now I have it set just to return player_id 1, but I want it to do player_id 2, 3, 4 etc depending on what linked name they click on.
I have been reviewing some documentation on sort by columns queries when clicking on a column header, and am thinking this is sort of the approach I should be taking, but I just can't seem to figure out the correct way to do it.
You can achieve this by passing a parameter to the view_picks_by_player.php page, and then PHP can pick up that parameter and generate content for the appropriate player.
For example, in the page where you select the player you want stats for you could have:
<a href='view_picks_by_player?id=player1'>Get Player 1's Stats!</a>
<a href='view_picks_by_player?id=player2'>Get Player 2's Stats!</a>
And then in the top of the view_picks_by_player.php page you could have:
$id = $_GET['id'];
$sql = "SELECT * FROM player_stats WHERE id = '$id'";
Obviously your SQL is structured differently, but this is just a quick way to show how you can pass a variable to the php page so it can generate different content dynamically.
For security, you'll want to validate that the user has not typed anything nasty into the URL as the 'id' before you use it in your SQL, but that's another topic...