“Insert if not exists” statement in SQLite

I have an SQLite database. I am trying to insert values (users_id, lessoninfo_id) in table bookmarks, only if both do not exist before in a row. INSERT INTO bookmarks(users_id,lessoninfo_id) VALUES( (SELECT _id FROM Users WHERE User=””+$(“#user_lesson’).html()+”‘), (SELECT _id FROM lessoninfo WHERE Lesson=”+lesson_no+” AND cast(starttime AS int)=”+Math.floor(result_set.rows.item(markerCount-1).starttime)+”) WHERE NOT EXISTS ( SELECT users_id,lessoninfo_id from bookmarks WHERE … Read more

Best way to do multi-row insert in Oracle?

I’m looking for a good way to perform multi-row inserts into an Oracle 9 database. The following works in MySQL but doesn’t seem to be supported in Oracle. INSERT INTO TMP_DIM_EXCH_RT (EXCH_WH_KEY, EXCH_NAT_KEY, EXCH_DATE, EXCH_RATE, FROM_CURCY_CD, TO_CURCY_CD, EXCH_EFF_DATE, EXCH_EFF_END_DATE, EXCH_LAST_UPDATED_DATE) VALUES (1, 1, ’28-AUG-2008′, 109.49, ‘USD’, ‘JPY’, ’28-AUG-2008′, ’28-AUG-2008′, ’28-AUG-2008′), (2, 1, ’28-AUG-2008′, .54, ‘USD’, … Read more

Postgres: INSERT if does not exist already

I’m using Python to write to a postgres database: sql_string = “INSERT INTO hundred (name,name_slug,status) VALUES (” sql_string += hundred + “, ‘” + hundred_slug + “‘, ” + status + “);” cursor.execute(sql_string) But because some of my rows are identical, I get the following error: psycopg2.IntegrityError: duplicate key value violates unique constraint “hundred_pkey” How … Read more