Skip to content

Querying data with sql statements instead of dataframe API? #6336

Answered by cpcloud
nikhilmakan02 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @nikhilmakan02 👋🏻! Welcome to ibis, and thanks for opening up a discussion about this.

is it possible to actually execute a given SQL statement against the backend of choice instead of using the Dataframe API?

Indeed it is possible.

You can do this with the Backend.sql method, or with the Table.sql method.

Backend.sql

In [7]: from ibis.interactive import *

In [8]: con = ibis.mssql.connect(user="sa", password="1bis_Testing!", database="ibis_testing")

In [9]: con.list_tables()
Out[9]: ['awards_players', 'batting', 'diamonds', 'functional_alltypes', 'win']

In [10]: con.sql("SELECT TOP 5 * FROM batting ORDER BY yearID")
Out[10]:
┏━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━┳…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@nikhilmakan02
Comment options

@gforsyth
Comment options

Answer selected by gforsyth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants