0

Is there an equivalent way to connect to a postgres database in a similar way that sqlite connects to a database using python?

For example, in sqlite, a connection will be defined by conn = sqlite3.connect(curruser.dbname). What is the similar connection syntax for postgres?

1
  • Which programming language are you using? Commented Aug 23, 2011 at 0:32

1 Answer 1

6

You can use the psycopg connector then, and the connection syntax will be similar, except that you'll need to specify some more information in a connection string:

conn_string = "host='localhost' dbname='my_database' user='postgres' password='secret'"
conn = psycopg2.connect(conn_string)

Here are some examples: Using psycopg2 with PostgreSQL

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.