I am inserting a record into a Amazon Redshift table from Python 2.7 using psycopg2 library and I would like to get back the auto generate primary id for the inserted row.
I have tried the usual ways I can find here or in other websites using google search, eg:
conn=psycopg2.connect(conn_str)
conn.autocommit = True
sql = "INSERT INTO schema.table (col1, col2) VALUES (%s, %s) RETURNING id;"
cur = conn.cursor()
cur.execute(sql,(val1,val2))
id = cur.fetchone()[0]
I receive an error on cur.execute line :
ProgrammingError: syntax error at or near "RETURNING"
Does anybody know how to fix this or accomplish the same thing?
I have to use psycopg2 in my code