4 ms·
It's a pity you can't do something similar to SQL: when writing UPDATE/DELETE always write the WHERE clause first
by yread 8y ago
It's a pity you can't do something similar to SQL: when writing UPDATE/DELETE always write the WHERE clause first
- rmetzler 8y agoSomething I learned early on when writing possible dangerous SQL selects: CREATE TABLE mytable_backup AS SELECT * FROM mytable; SELECT * FROM mytable WHERE condition; DELETE FROM mytable WHERE condition;
- traviscj 8y agoOr just let the DB work for you with BEGIN; + (select/update/delete) + COMMIT; or ROLLBACK;
- jolmg 8y agoWhat I like about SQL is that it's got the double safety of ";". To accidentally run a SQL statement before it's ready in a command line, you'd have to both add the ";" AND hit Enter, or have the bad practice of adding ";" before the statement is ready, or use a bad SQL command line that sees the ";" as optional.
- groestl 8y agoI always start a session with BEGIN, write UPDATEs/DELETEs as SELECTs first and (if possible) use a staging database until I'm fine with the result.
- amalcon 8y agoIn SQL, you can at least wrap the whole thing in a transaction. Then, just roll the whole thing back if anything came out wrong.
- inopinatus 8y agoI usually SELECT COUNT(*) WHERE ..., and only subsequently overwrite with DELETE.