I have a problem with PostgreSQL where I can generate a UID for an entry but I don't know how to get this UID out so that I can use it in python.
This is an example of me generating a table:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
create table example(
id UUID NOT NULL PRIMARY KEY,
dict JSON NOT NULL
);
I use psycopg2 to connect to the database which I can do fine (note that I am omitting the connection code as it is not relevant) . Then execute a query to insert a new record as follows
cur = conn.cursor()
cur.execute("INSERT INTO example(id, dict) values (uuid_generate_v4(),'" + json.dumps(data) + "')")
conn.commit()
where data is just a sample dictionary.
I want to be able to get the UID I just generated so that I can print it or store it in a file etc. I would prefer to avoid just taking the last record in case multiple users are accessing the database at once.
Does anyone know a way to get this information out from a query?