My postgres query is:
query = """INSERT INTO statustable(value) SELECT '%s'
WHERE NOT EXISTS (SELECT id, value FROM statustable
WHERE value = '%s') RETURNING id""" % (status, status)
cursor_postgres.execute(query)
conn_postgres.commit()
statusId = cursor_postgres.fetchone()[0]
print "statusId" + str(statusId)
I need to get the freshly inserted status value id if it doesnt exist, or select its id if already exist. RETURNING id choked this query entirely so I had to remove it to atleast get the selective insertion working.
Any clues how to get the statusId here? In another instance I am doing an Upsert.(Insert if not exist, update otherwise) Here again, I need the inserted or updated row id. (No, I am not using stored procedures, if that was your first question...)
Thanks in advance
INSERT INTO statustable (value), '%s' RETURNING id" %(status)as this will also return the id. But I was looking for putting this all into one.