Ich bin wie so eine Tabelle bevölkern:Einfügen UUID in Tabelle erzeugt - nicht Typ UUID anpassen
...
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)
Mit der folgenden Tabelle Definition:
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;
Jedoch gibt dies mir folgenden Fehler: can't adapt type 'UUID'
. Was wäre der Grund dafür? Ich brauche die time_id
und location_id
, um eindeutig zu sein, da sie als Fremdschlüssel zwischen einer Dimension und einer Faktentabelle fungieren.
Gibt es einen Grund, warum Sie den UUID-Datentyp nicht zum Speichern von UUIDs verwenden? https://www.postgresql.org/docs/9.1/static/datatype-uuid.html – Ivan