I'm populating a table like so:
...
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)
With the following table 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;
However this gives me the following error: can't adapt type 'UUID'
. What would the reason for this be? I need the time_id
and location_id
to be unique as they act as a foreign key between a dimension and fact table.
uuid is a particular type which looks like a string, but isn't. You're trying to put it into a character field. You need to convert it to a string first: str(time_id), str(location_id)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With