Home > Software design >  psycopg2 OperationalError
psycopg2 OperationalError

Time:09-22

        import psycopg2

def creat_tabel():
    conn=psycopg2.connect("dbname='database1' user='postgres' password='postgres123' host='localhost' port='5432' ")
    cur=conn.cursor()
    cur.execute("CREATE TABLE İF NOT EXISTS store (item TEXT , quantity INTEGER , price REAL)")
    conn.commit()
    conn.close()

creat_tabel()

This is my code and this is my error. How can I fix it? Please help.

C:\Users\sinan urgun\Desktop\python\db>script2_postgresql.py                                                                                                    
Traceback (most recent call last):                                                                                                                              
  File "C:\Users\sinan urgun\Desktop\python\db\script2_postgresql.py", line 10, in <module>                                                                     
    creat_tabel()                                                                                                                                               
  File "C:\Users\sinan urgun\Desktop\python\db\script2_postgresql.py", line 4, in creat_tabel                                                                   
    conn=psycopg2.connect("dbname='database1' user='postgres' password='postgres123' host='localhost' port='5432' ")                                            
  File "C:\Users\sinan urgun\AppData\Local\Programs\Python\Python39\lib\site-packages\psycopg2\__init__.py", line 122, in connect                               
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)                                                                                      
psycopg2.OperationalError  

CodePudding user response:

You have a typo in your SQL. You have written "İF", where that first character is U 0130 : LATIN CAPITAL LETTER I WITH DOT ABOVE. You want to write "IF" instead.

You can see the dot above the I in your question; you should also be able to see this in your local editor. If this is a regular problem you may want to experiment with different fonts that make the issue more obvious.

  • Related