vmware-archive / sql_magic

Magic functions for using Jupyter Notebook with Apache Spark and a variety of SQL databases.
Apache License 2.0
172 stars 21 forks source link

Q: Way to use a conn at line magic? #9

Open tkang007 opened 6 years ago

tkang007 commented 6 years ago

Hi, Wonderful project for SQL at Jupyter. Let me add a question with below usage case.

Usage senario: With cell magic, "drop if exist tmptab; creat temp tab" failed as no table. it might be failed as it execute as a statement i postgres+psycopg2 env.

With two cell magic using a connection, it is okay.

With two line magic, how to specify a specific connection.

When engine configed with threadlocal and max 1, overflow 0, this case can be solved.

But, I like to use line magic in a function(not in cell magic) and parallel model for this case.

Thanks, Taewon

crawles commented 6 years ago

Hi Taewon, it can be done, this line needs to have the argument parsing added to it. I'm a bit over committed time-wise right now, but it you want to give it a crack happy to do code review.

tkang007 commented 5 years ago

Thanks for your comment and sorry for late response.

Vikram2712 commented 5 years ago

what is connect credentials and where it is defined because when i am trying execute the it gives output as a connect credential is not defined. please clear my concept regarding that

scottcode commented 5 years ago

@Vikram2712 The connect_credentials variable as shown in the example in the README is a simple dictionary whose keys are user, password, host, and database. If you are trying to connect to a database other than Postgres, see the sqlalchemy documentation for create_engine. Does that help clarify?

Vikram2712 commented 5 years ago

just take an example like (database ="project",user ="postgres", password ="vikram@12",host ="localhost",port ="5432") so, how to write with the help of %%load_ext. sql that thing is not understable by me because when i try it is showing some type of error below is the screenshot of my code will u please sortout this problem. 1

scottcode commented 5 years ago

@Vikram2712, I encourage you to look at the example Jupyter notebook in the repo: sql_magic API.ipynb. In your case, it looks like the output isn't based on what is currently in the cell. There was conn2 = psycopg2.connect(**connect_credentials). You need to add that back in, as well as define a dictionary named connect_credentials. Again, see the notebook example for how to do that.