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?
asked Aug 23, 2011 at 0:23
locoboy
39.1k73 gold badges190 silver badges264 bronze badges
-
Which programming language are you using?alf– alf2011年08月23日 00:32:14 +00:00Commented Aug 23, 2011 at 0:32
1 Answer 1
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
answered Aug 23, 2011 at 0:37
alf
18.6k10 gold badges64 silver badges93 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default