Reputation: 97
After much hassle with getting the POSTGRESQL program configured with a user with a capital letter and figuring out how to write out an abs path in windows:
set DATABASE_URL=postgresql:///c:\\Program Files\\PostgreSQL\\9.3\\data\\books.db
(no spaces ! I learned this the hardway !)
in Windows I am still having difficulty connecting to the local databse I created with a test script I have.
within PSQL there exists a database called 'books' which shows up with '\z'. The default directory for saving databases has not been changed from POSTGRESQL default. and yet when I run the program :
import csv
import os
from sqlalchemy_utils import database_exists
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
def import_csv():
f = open("books.csv")
reader = csv.reader(f)
for isbn, title, author, year in reader:
db.execute("INSERT INTO books (isbn, title, author, year) VALUES (:isbn, :title, :author, :year)",
{"isbn":isbn, "title":title, "author":author, "year":year})
db.commit()
import_csv()
Why does this not connect ? ( I have cut out a lot of extraneous code here to show the active parts I am dealing with)
Upvotes: 1
Views: 6753
Reputation: 311606
After much hassle with getting the POSTGRESQL program configured with a user with a capital letter and figuring out how to write out an abs path in windows: set DATABASE_URL=postgresql:///c:\Program Files\PostgreSQL\9.3\data\books.db
Postgres is a database server. You can't connect directly to one of the underlying files like that. You need to connect to the network service provided by the Postgres database server.
The acceptable SQLAlchemy URLs for connecting to a Postgres database are shown here.
Upvotes: 4