Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example notebook for [PostgreSQL and Jupyter notebook on Windows](https://medium.com/@FranckPachot/postgresql-and-jupyter-notebook-on-windows-e7b68cb6427d)\n",
"\n",
"## (Blog by Franck Pachot)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## I restart the PostgreSQL server and re-create the DEMO database\n",
"Because I use this for repeatable demos, I restart and re-create the database"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"waiting for server to start....2019-04-28 19:52:33.255 CEST [104] LOG: listening on IPv6 address \"::1\", port 5432\r\n",
"2019-04-28 19:52:33.255 CEST [104] LOG: listening on IPv4 address \"127.0.0.1\", port 5432\r\n",
"2019-04-28 19:52:33.301 CEST [4656] LOG: database system was shut down at 2019-04-28 19:52:27 CEST\n",
"2019-04-28 19:52:33.354 CEST [104] LOG: database system is ready to accept connections\r\n",
" done\r\n",
"server started\r\n",
"DROP DATABASE\r\n",
"CREATE DATABASE\r\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"+ pg_ctl.exe restart '--pgdata=C:\\Anaconda\\pgdata'\n",
"pg_ctl: PID file \"C:/Anaconda/pgdata/postmaster.pid\" does not exist\r\n",
"Is server running?\r\n",
"trying to start server anyway\r\n",
"+ psql.exe -c 'drop database if exists DEMO;' postgres\n",
"+ psql.exe -c 'create database DEMO;' postgres\n"
]
}
],
"source": [
"%%bash -x\n",
"pg_ctl.exe restart --pgdata=\"C:\\Anaconda\\pgdata\"\n",
"psql.exe -c \"drop database if exists DEMO;\" postgres\n",
"psql.exe -c \"create database DEMO;\" postgres"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## I load the library and connect to DEMO\n",
"I use `%reload_ext` to avoid the \"The sql extension is already loaded.\" error with `%load_ext`"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Connected: @demo'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%reload_ext sql\n",
"%sql postgresql://localhost/demo "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I can see that I run the latest PostgreSQL release:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * postgresql://localhost/demo\n",
"1 rows affected.\n",
"+------------------------------------------------------------+\n",
"| version |\n",
"+------------------------------------------------------------+\n",
"| PostgreSQL 11.2, compiled by Visual C++ build 1915, 64-bit |\n",
"+------------------------------------------------------------+\n"
]
}
],
"source": [
"pg_version=%sql select version()\n",
"print(pg_version)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## I create my demo table\n",
"Yes, I like the SCOTT/TIGER schema from Oracle...\n",
"I can run many statements but all output is displayed at the end:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * postgresql://localhost/demo\n",
"Done.\n",
"Done.\n",
"Done.\n",
"Done.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n"
]
},
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"drop table if exists EMP;\n",
"drop table if exists DEPT;\n",
"CREATE TABLE DEPT\n",
" (DEPTNO integer CONSTRAINT PK_DEPT PRIMARY KEY,\n",
" DNAME text ,\n",
" LOC text ) ;\n",
"CREATE TABLE EMP\n",
" (EMPNO integer CONSTRAINT PK_EMP PRIMARY KEY,\n",
" ENAME text,\n",
" JOB text,\n",
" MGR integer,\n",
" HIREDATE date,\n",
" SAL integer,\n",
" COMM integer,\n",
" DEPTNO integer CONSTRAINT FK_DEPTNO REFERENCES DEPT);\n",
"INSERT INTO DEPT VALUES (10,'ACCOUNTING','NEW YORK');\n",
"INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS');\n",
"INSERT INTO DEPT VALUES (30,'SALES','CHICAGO');\n",
"INSERT INTO DEPT VALUES (40,'OPERATIONS','BOSTON');\n",
"INSERT INTO EMP VALUES (7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);\n",
"INSERT INTO EMP VALUES (7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);\n",
"INSERT INTO EMP VALUES (7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);\n",
"INSERT INTO EMP VALUES (7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);\n",
"INSERT INTO EMP VALUES (7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);\n",
"INSERT INTO EMP VALUES (7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30);\n",
"INSERT INTO EMP VALUES (7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);\n",
"INSERT INTO EMP VALUES (7788,'SCOTT','ANALYST',7566,to_date('13-7-1987','dd-mm-yyyy')-85,3000,NULL,20);\n",
"INSERT INTO EMP VALUES (7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);\n",
"INSERT INTO EMP VALUES (7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);\n",
"INSERT INTO EMP VALUES (7876,'ADAMS','CLERK',7788,to_date('13-7-1987', 'dd-mm-yyyy')-51,1100,NULL,20);\n",
"INSERT INTO EMP VALUES (7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30);\n",
"INSERT INTO EMP VALUES (7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20);\n",
"INSERT INTO EMP VALUES (7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## PSQL special commands\n",
"Thanks to the PGspecial plug-in I can use the 'backslash' commands"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * postgresql://localhost/demo\n",
"2 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>Schema</th>\n",
" <th>Name</th>\n",
" <th>Type</th>\n",
" <th>Owner</th>\n",
" </tr>\n",
" <tr>\n",
" <td>public</td>\n",
" <td>dept</td>\n",
" <td>table</td>\n",
" <td>Franck</td>\n",
" </tr>\n",
" <tr>\n",
" <td>public</td>\n",
" <td>emp</td>\n",
" <td>table</td>\n",
" <td>Franck</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[('public', 'dept', 'table', 'Franck'), ('public', 'emp', 'table', 'Franck')]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql \\dt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## I query some rows with SQL\n",
"It is easy to stay in the best practices: use bind variables!"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * postgresql://localhost/demo\n",
"3 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>deptno</th>\n",
" <th>dname</th>\n",
" <th>loc</th>\n",
" <th>empno</th>\n",
" <th>ename</th>\n",
" <th>job</th>\n",
" <th>mgr</th>\n",
" <th>hiredate</th>\n",
" <th>sal</th>\n",
" <th>comm</th>\n",
" </tr>\n",
" <tr>\n",
" <td>10</td>\n",
" <td>ACCOUNTING</td>\n",
" <td>NEW YORK</td>\n",
" <td>7782</td>\n",
" <td>CLARK</td>\n",
" <td>MANAGER</td>\n",
" <td>7839</td>\n",
" <td>1981-06-09</td>\n",
" <td>2450</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10</td>\n",
" <td>ACCOUNTING</td>\n",
" <td>NEW YORK</td>\n",
" <td>7839</td>\n",
" <td>KING</td>\n",
" <td>PRESIDENT</td>\n",
" <td>None</td>\n",
" <td>1981-11-17</td>\n",
" <td>5000</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10</td>\n",
" <td>ACCOUNTING</td>\n",
" <td>NEW YORK</td>\n",
" <td>7934</td>\n",
" <td>MILLER</td>\n",
" <td>CLERK</td>\n",
" <td>7782</td>\n",
" <td>1982-01-23</td>\n",
" <td>1300</td>\n",
" <td>None</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(10, 'ACCOUNTING', 'NEW YORK', 7782, 'CLARK', 'MANAGER', 7839, datetime.date(1981, 6, 9), 2450, None),\n",
" (10, 'ACCOUNTING', 'NEW YORK', 7839, 'KING', 'PRESIDENT', None, datetime.date(1981, 11, 17), 5000, None),\n",
" (10, 'ACCOUNTING', 'NEW YORK', 7934, 'MILLER', 'CLERK', 7782, datetime.date(1982, 1, 23), 1300, None)]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"deptno=10\n",
"%sql select * from DEPT join EMP using (DEPTNO) where deptno=:deptno"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"By default, the output is nicely formated in an HTML table\n",
"\n",
"The previous result is accessible with `_` and can be displayed as an ASCII table"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+--------+------------+----------+-------+--------+-----------+------+------------+------+------+\n",
"| deptno | dname | loc | empno | ename | job | mgr | hiredate | sal | comm |\n",
"+--------+------------+----------+-------+--------+-----------+------+------------+------+------+\n",
"| 10 | ACCOUNTING | NEW YORK | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450 | None |\n",
"| 10 | ACCOUNTING | NEW YORK | 7839 | KING | PRESIDENT | None | 1981-11-17 | 5000 | None |\n",
"| 10 | ACCOUNTING | NEW YORK | 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300 | None |\n",
"+--------+------------+----------+-------+--------+-----------+------+------------+------+------+\n"
]
}
],
"source": [
"print(_)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I can access to the first row:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(10, 'ACCOUNTING', 'NEW YORK', 7782, 'CLARK', 'MANAGER', 7839, datetime.date(1981, 6, 9), 2450, None)\n"
]
}
],
"source": [
"print(_[0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I can display the column names:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['deptno', 'dname', 'loc', 'empno', 'ename', 'job', 'mgr', 'hiredate', 'sal', 'comm']\n"
]
}
],
"source": [
"print(_.keys)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I can access to one column by index or by name:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CLARK\n",
"1981-06-09\n"
]
}
],
"source": [
"print(_[0][4])\n",
"print(_[0]['hiredate'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## I display some values graphically\n",
"We can use mathplotlib .plot(), .pie(), and .bar()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * postgresql://localhost/demo\n",
"3 rows affected.\n"
]
},
{
"data": {
"text/plain": [
"<BarContainer object of 3 artists>"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAE3CAYAAAC9wabBAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAHw5JREFUeJzt3XmYpFV99vHvLSCKkogyEAR0VEYjXirqgKhxCW6IMUhcAIkQJUENuLyaGFwSXF4UcYsLYkCIYBQkbmBEAQkuvBFhQIICAiMQGSEyiisKyPB7/zintYRh6Ae6urp7vp/r6qurTp2qPj093Xc9Z01VIUnSdN1p0g2QJM0vBockaRCDQ5I0iMEhSRrE4JAkDWJwSJIGMTgkSYMYHJKkQQwOSdIgBockaZB1x/XCSe4CfA1Yv3+dT1XVAUnuBxwL3BM4B3hhVd2QZH3gaOBRwI+BXavq8v5arwP2BlYBr6iqk9b0tTfeeONavHjxWL4vSVqozj777B9V1aLbqje24ACuB3aoql8mWQ84PckXgVcD762qY5N8mBYIh/bPP6mqrZLsBrwD2DXJ1sBuwEOAewNfTvLAqlp1a1948eLFLFu2bIzfmiQtPEn+Zzr1xtZVVc0v+931+kcBOwCf6uVHAc/ut3fu9+mPPzlJevmxVXV9VV0GLAe2G1e7JUlrNtYxjiTrJDkXuBo4Bfge8NOqurFXWQFs3m9vDlwB0B//GXCv0fLVPEeSNMvGGhxVtaqqtgG2oF0lPHh11frn3Mpjt1b+e5Lsk2RZkmUrV668vU2WJN2GWZlVVVU/Bb4CbA/cI8nU2MoWwJX99gpgS4D++B8C14yWr+Y5o1/jsKpaWlVLFy26zbEdSdLtNLbgSLIoyT367bsCTwEuBE4Dntur7Q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gWbdR/w+Bq6rqJuCFwDoDv97JwH5Td/qVizRRBoc0QFWdA3wSOBf4NO2slTX5ELBXkjNo3VTXDvySrwCWJjkvyQXASwc+X5pxbnIoSRrEKw5J0iAGhyRpEINDkjSIwSFJGsTgkCQNYnBIkgYxOCRJgxgckqRB/j8RuTlhjQwUywAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"r=%sql select dname,avg(sal) from DEPT join EMP using (DEPTNO) group by dname\n",
"%matplotlib inline\n",
"r.bar()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.