Skip to content
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

Possible to loop over rows without pulling entire table? #155

Closed
McNees287 opened this issue Jan 4, 2017 · 3 comments
Closed

Possible to loop over rows without pulling entire table? #155

McNees287 opened this issue Jan 4, 2017 · 3 comments

Comments

@McNees287
Copy link

McNees287 commented Jan 4, 2017

I need to work with several large database tables in Julia. Executing the query currently takes a long time due to all of the data being transferred (using ODBC.query). Does ODBC.jl have a way to loop over individual rows in a sequential manner, similar to readline() when working with text files, or Pyodbc's fetchone?

I think there might be some functionality available that can be used here, but I can't fully parse the documentation.

Thanks for making this package.

@quinnj
Copy link
Member

quinnj commented Jan 4, 2017

Yes, currently you can do something like:

source = ODBC.Source(dsn, query) # executes the query against the DB and returns initial result chunk
types = Data.types(source)
row = col = 1
while !Data.isdone(source, row, col)
    for col = 1:size(source, 2)
        val = Data.streamfrom(source, Data.Field, types[col], row, col)
    end
end

Obviously this isn't super pretty, but indeed possible. Suggestions for a better API? I mean, we could define the iteration protocol on an ODBC.Source to return an entire row as a tuple, maybe that would be best.

@McNees287
Copy link
Author

McNees287 commented Jan 4, 2017

Cool. Let me play around with this for a bit.

I agree there should be a cleaner way to implement this. I think it's a valuable feature.

@quinnj
Copy link
Member

quinnj commented May 24, 2020

You can now do DBInterface.execute(conn, sql; iterate_rows=true) to ensure only a single row gets buffered into memory at a time for resultsets.

@quinnj quinnj closed this as completed May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants