I am using a simple python script to connect the postgresql and future will create the table into the postgresql just using the script.
My code is:
try:
conn = "postgresql://postgres:<password>@localhost:5432/<database_name>"
print('connected')
except:
print('not connected')
conn.close()
when I run python connect.py (my file name), it throws this error :
Instance of 'str' has no 'commit' member
pretty sure is because it detects 'conn' as a string instead of database connection. I've followed this documentation (33.1.1.2) but now sure if Im doing it right. How to correct this code so it will connect the script to my postgresql server instead of just detects it as a string?
p/s: Im quite new to this.
connis definitely a string, and therefore has nocommit()orclose()method. Its value is"postgresql://postgres:<password>@localhost:5432/<database_name>". Did you mean something likeconn = psycopg2.connect("postgresql://postgres:<password>@localhost:5432/<database_name>")?libpq, whose documentation you linked to, is a C library, not a Python library.commit()in it. Please make sure to provide a minimal reproducible example when asking questions here.