1
我填充像這樣的表:插入生成的UUID到表 - 無法適應型UUID
...
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的原因? https://www.postgresql.org/docs/9.1/static/datatype-uuid.html – Ivan