Skip to content

Instantly share code, notes, and snippets.

@catherinedevlin
Created March 29, 2013 18:34
Show Gist options
  • Save catherinedevlin/5272681 to your computer and use it in GitHub Desktop.
Save catherinedevlin/5272681 to your computer and use it in GitHub Desktop.
ipython-sql %%sql magic demonstration
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "writers"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"%load_ext sql"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%sql sqlite://"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "pyout",
"prompt_number": 4,
"text": [
"'Connected: None@None'"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sql\n",
"CREATE TABLE writer (first_name, last_name, year_of_death);\n",
"INSERT INTO writer VALUES ('William', 'Shakespeare', 1616);\n",
"INSERT INTO writer VALUES ('Bertold', 'Brecht', 1956);"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "pyout",
"prompt_number": 5,
"text": [
"[]"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%sql select * from writer"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<table>\n",
" <tr>\n",
" <th>first_name</th>\n",
" <th>last_name</th>\n",
" <th>year_of_death</th>\n",
" </tr>\n",
" <tr>\n",
" <td>William</td>\n",
" <td>Shakespeare</td>\n",
" <td>1616</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Bertold</td>\n",
" <td>Brecht</td>\n",
" <td>1956</td>\n",
" </tr>\n",
"</table>"
],
"output_type": "pyout",
"prompt_number": 6,
"text": [
"[('William', 'Shakespeare', 1616), ('Bertold', 'Brecht', 1956)]"
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment