【发布时间】:2018-09-01 21:06:58
【问题描述】:
我正在使用 python 的 odo 将数据从 pandas 数据框移动到 postgresql 数据库。目标是每个“用户”在他们的模式中看到他们自己的数据,但在“用户”之间具有相同的数据模型和表/视图命名模式。使用普通 SQL 我可以做到这一点:
CREATE SCHEMA my_schema;
CREATE TABLE my_schema.my_table AS select 1;
我的 DB URI 如下所示
db_uri = 'postgresql://localhost/postgres::my_schema.my_table'
这为我提供了名为“my_schema.my_table”的default 架构中的表,包括“。”在表名中,而不是模式“my_schema”中名为“my_table”的表。
我根据这个github issue尝试了不同的组合,比如:
db_uri = 'postgresql://localhost/postgres.schema::tmp')
这给了我这个 Traceback
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: database "postgres/schema" does not exist
还有这个
db_uri = 'postgresql://localhost/postgres::my_schema/my_table'
这给了我名为“my_schema/my_table”的表。
这是一个示例代码:
import pandas as pd
from odo import odo
db_uri = 'postgresql://localhost/postgres::my_schema.my_table'
odo(pd.DataFrame([{'a': 1}, {'a': 1}]), db_uri)
【问题讨论】:
标签: python postgresql pandas blaze odo