3

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?

DannyDannyDanny
  • 838
  • 9
  • 26
dani shamir
  • 81
  • 1
  • 9

1 Answers1

6

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.

Cito
  • 5,365
  • 28
  • 30
  • Thanks for that. I added: cur.execute('SET search_path TO bidba, public'), but still getting same error – dani shamir Jul 12 '20 at 05:42
  • Did you pass tbl = 'upmeta' (i.e. without a dot)? The table name casing matters as well. If it has been created as "Upmeta" or "UpMeta" it will now work. – Cito Jul 12 '20 at 10:43
  • It works now. I passed only the table name without the schema. Thanks so much ! – dani shamir Jul 14 '20 at 06:35