我想在Postgres中的同一个DB中只将4个表从schema1复制到schema2.并且希望将表保留在schema1中.知道如何在pgadmin和postgres控制台中做到这一点?
我正在尝试使用此psycopg2使用 cursor.mogrify 将大量行插入 postgres :insert multiple rows with a query
data 是一个元组列表,其中每个元组是需要插入的一行。
cursor = conn.cursor()
args_str = ','.join(cursor.mogrify("(%s,%s,%s,%s,%s,%s,%s,%s)", x) for x in data)
cursor.execute(
"insert into table1 (n, p, r, c, date, p1, a, id) values " + args_str)`
Run Code Online (Sandbox Code Playgroud)
但得到错误:
TypeError: sequence item 0: expected str instance, bytes found
Run Code Online (Sandbox Code Playgroud)
在线:
args_str = ','.join(cursor.mogrify("(%s,%s,%s,%s,%s,%s,%s,%s)", x) for x in data)
Run Code Online (Sandbox Code Playgroud)
如果我尝试更改为b''.join(cursor.mogrify("(%s,%s,%s,%s,%s,%s,%s,%s)", x) for x in data ),然后执行查询给出插入字节的错误....
难道我做错了什么 ?