#799

Insert a batch of notifications and grab the ids

You're broadcasting notifications to several users at once. Inserting one row at a time means four round-trips plus the risk of the service restarting between them. One INSERT with multiple values plus returning the generated ids solves both. The table notifications(id SERIAL, user_id, msg) is empty. Add four rows in a single statement: (user_id = 1, msg = 'hello'), (user_id = 2, msg = 'hi'), (user_id = 1, msg = 'again'), (user_id = 3, msg = 'welcome') — and in the same statement return the generated id values along with the user_id.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.

iduser_id
11
22
31

Your query result will appear here