【发布时间】:2017-05-01 17:35:34
【问题描述】:
我正在填充这样的表格:
...
time_id = uuid.uuid4()
location_id = uuid.uuid4()
id = row['id']
sql = '''
INSERT INTO "my-schema"."example"(
...
time_id,
location_id
id
) VALUES (..., %s, %s, %s)
'''
data = (..., time_id, location_id, id)
try:
my_cursor.execute(sql, data)
my_conn.commit()
except (psycopg2.Error) as e:
print(e)
有如下表定义:
CREATE TABLE "my-schema".example
(
...
time_id character varying(50),
location_id character varying(50),
CONSTRAINT "PK_example" PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE "my-schema".example
OWNER TO postgres;
但是,这给了我以下错误:can't adapt type 'UUID'。这是什么原因?我需要 time_id 和 location_id 是唯一的,因为它们充当维度和事实表之间的外键。
【问题讨论】:
-
您是否有理由不使用 UUID 数据类型来存储 UUID? postgresql.org/docs/9.1/static/datatype-uuid.html
标签: python sql postgresql