Database / SQLite Interview questions
What is an UPSERT in SQLite (INSERT... ON CONFLICT)?
An upsert inserts a new row, or updates an existing one instead if the insert would violate a uniqueness constraint — a single statement covering both the "create" and "update" case, avoiding a separate check-then-insert-or-update sequence in application code.
INSERT INTO person (id, name, visit_count) VALUES (1, 'Ada', 1) ON CONFLICT(id) DO UPDATE SET visit_count = visit_count + 1;
ON CONFLICT(column) DO UPDATE SET ... specifies exactly what to do when a conflicting row
already exists, and can reference the conflicting existing row's values via excluded.column for
the values that were about to be inserted. There's also a simpler DO NOTHING variant when you
just want to silently skip the insert on conflict rather than updating anything.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
