When accessing a database using
psycopg2, we first have to specify which database we are going to use. This means that the database must exist before your Python code can use it. To set everything up, we'll use the Postgres command-line utilities. Type the following into your terminal or command-line window:
% createdb world_borders
Don't forget to include the
-U postgres option, or
sudo, if you need to access Postgres under a different user account.
This creates the database itself. We next want to enable the PostGIS spatial extension for our database. To do this, enter the following command:
% psql -d world_borders -c "CREATE EXTENSION postgis;"
Now that we've set up the database itself, let's create the table within ...