-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Querying AGE3 database #3
Comments
I got this from Jon and connected to AGE3 using it. I was able to see the tables, I just didn't know how to query properly. dbconnection <- odbcDriverConnect("Driver={SQL Server};Server={AKC0SS-VI-071.nmfs.local,1919};Database=AGE3;Trusted_Connection=yes;") |
Oh that's awesome! I think the function I put in there may let us query then, just by updating the table names from RACEBASE tables to the appropriate AGE3 table. I'll check this out today and let you know how it works. |
Cool, thank you both for sharing this. For querying, I found this page that might be useful? I haven't tried any of it yet. |
So I tried the code you provided in combo with stuff from that link I sent and I think this will do it; we just have to make sure we're adjusting the querying for the relevant tables. This is a simple example but it works. #Test querying from age3 library(RODBC) #establish connection #see table names #try a query qry <- "SELECT * FROM survey_cruises WHERE cruise_number = 197902" odbcCloseAll() #closes connection |
The hardest thing will probably be getting the SQL commands right (if you're like me and not used to using them) |
So, I started delving a little deeper and it looks like we may need to join tables prior to querying the data we want. I looked at the "nir_scans" table and it doesn't appear that you can query by species (other than maybe by parsing it from the scan name, although this seems like a pain) or other collection variables. Here's the table structure.
And I couldn't really tell in which table we could find the traditional age data. Should I start an email thread with Jon, or does he have a github account? |
Thanks for delving into this! Jon does have a really great schematic of the database on the wall in his office, and also has a Github account @JonShort4. |
Thanks, Beth! Oh interesting. Looks like there isn't a "species" field in the NIR data table. I wonder if that's something that would be fairly straightforward to add to make querying easier? Definitely a question for Jon. |
Hi @JonShort4, we are learning how to query from age3 directly in R and have a few questions about the tables that came up in the comment thread above. When you have a chance, could you look this over and maybe we could have a follow-up conversation next week? |
Hi guys, yeah we should have a conversation about this before you put much effort into it. I already have data views that join tables and make querying very easy. We should meet though to make sure they provide what you are looking for. |
Sweet! That would be excellent. What day/time would be good for everyone? I could do this afternoon or pretty much any time next week. |
I'm sure you're all way ahead of me, but just in case you need to join tables in your query, here's a way to do it. This joins the "fish with ages" view to the species and survey cruises tables. I was not very familiar with SQL queries prior to this, so it was a learning experience for me and would love to spare you some grief if you're in a similar boat. library(RODBC) #set up query #Query from age3 #age data odbcClose(dbconnection) |
@BethMatta-NOAA @EstherDGoldstein-NOAA
Starting a thread about trying to query directly from the AGE3 database to pull data into R. Talking with both of you, it sounds like this is something that would help all of us streamline things. There is some draft code at the top of the "Read Opus Files in R" script in this repository. I repurposed this chunk from code I've used to query the RACEBASE database and haven't yet tried to make this connection with AGE3. I wonder if we will need to work with Jon to make sure we have the right permissions? I have no idea how it works to get set up initially. For RACEBASE, it required working with IT and getting a username and password.
The text was updated successfully, but these errors were encountered: