pygresql copy_from gives a relation does not exist error

3.7k Views Asked by At

I have the following code

pg_con = conns.con_to_pg()
cur = pg_con.cursor()

with open('up_md.csv', 'r') as f:
    next(f)  # Skip the header row.
    tbl = 'bidba.upmeta'
    cur.copy_from(f, tbl, 'csv', sep=',')

pg_con.commit()

The schema and table bidba.upmeta exist in my postgres db. No matter what I do, I get the message: relation "bidba.upmeta" does not exist error.

I tried writing it with single quotes, double quotes, without quotes. Nothing helps. What am I missing? Is there an issue with the copy_from method?

1

There are 1 best solutions below

3
Cito On

This is a known issue and will be fixed in the next version of PyGreSQL.

As a workaround, you can pass tbl = 'upmeta'. This should work if your bidba schema is in the search path. Otherwise, you can put it into the search path for the current session with SET search_path TO bidba, public before calling copy_from.