Python Forum
Create table with psycopg2 on postgreSQL DB
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create table with psycopg2 on postgreSQL DB
#1
Hello everyone, that's my first time on this forum, but maybe not the last:

I have a problem, i want to create a table in a postgreSQL DB that i created. When i launch my program to create this table, i recieve a psycopg2.Operationalerror with no information about this error. Maybe someone can help me ?
Thank you very much.

import psycopg2
def create_table():
    conn=psycopg2.connect("dbname='DB1' user='postgres' password='shakD6yc' host='localhost' port='5432'")   
    cur=conn.cursor()      
    cur.execute("CREATE TABLE IF NOT EXISTS store (item TEXT, quantity INTEGER, price REAL)") 
    conn.commit()
    conn.close()
  
create_table()    
And this is what appears in my console when i launch:
Error:
Traceback (most recent call last): File "C:\Users\Yonathan\source\repos\PostgreSQL - Python\PostgreSQL - Python\PostgreSQL___Python.py", line 60, in <module> create_table() File "C:\Users\Yonathan\source\repos\PostgreSQL - Python\PostgreSQL - Python\PostgreSQL___Python.py", line 8, in create_table conn=psycopg2.connect("dbname='DB1' user='postgres' password='shakD6yc' host='localhost' port='5432'") File "C:\Users\Yonathan\Anaconda3\lib\site-packages\psycopg2\__init__.py", line 126, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError
Reply
#2
Error shows that it either couldn't connect, or perhaps a connection timed out.
Reply
#3
the parameters have to be separated by ,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Connect to PostgreSQL Through Jump Server and SSH Tunnel using Python? nishans 1 843 Jan-02-2024, 10:37 AM
Last Post: khanzain
  How to create a table with different sizes of columns in MS word pepe 8 1,414 Dec-08-2023, 07:31 PM
Last Post: Pedroski55
  group by create pivot table python dawid294 1 1,258 Jun-22-2022, 06:13 PM
Last Post: Larz60+
  How psycopg2 autocommit works ? johntay 3 10,205 Oct-08-2021, 11:22 AM
Last Post: Larz60+
  Psycopg2 doesn't work with python2 MedianykEugene 3 2,888 Aug-10-2021, 07:00 AM
Last Post: ndc85430
  How to create db table with SQLite and SQLAlchemy?? marcello86 1 2,272 Sep-02-2020, 03:05 PM
Last Post: marcello86
  maintain a postgresql database using osm2pgsql apollo 1 2,255 Aug-03-2020, 10:33 PM
Last Post: Larz60+
  PostgreSQL psycopg2.errors.DuplicateColumn: column specified more than once rajnish_nationfirst 2 3,691 Jun-21-2020, 08:17 AM
Last Post: ibreeden
  StopIteration exception when mock PostgreSQL connection in several tests igor87z 1 2,879 Jun-10-2020, 06:16 PM
Last Post: ibreeden
  Create new column in new created table farhana88 1 1,781 Jun-09-2020, 07:20 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020