Reputation: 81
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?
Upvotes: 3
Views: 4242
Reputation: 21
Also, you can fix like this:
1.
set_schema = "set schema 'bidba' "
cur.execute(set_schema)
cur.copy_from(f, 'upmeta', 'csv', sep=',')
Upvotes: 0
Reputation: 5613
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
.
Upvotes: 6