4 ms·
Could i add my slight tangent tip. Sql(delete,updates etc) I got into habbit of writing my sql as 'zdelete from product where id = 123;' and THEN i remove the
by rawoke083600 4y ago
Could i add my slight tangent tip. Sql(delete,updates etc)
I got into habbit of writing my sql as
'zdelete from product where id = 123;' and THEN i remove the prefixed-z.
Too many a time i copy and pasted wrong ids or screwed up something else.
- iforgotpassword 4y agoI write them as SELECT Count(*) FROM product WHERE id = 123 And if the number looks right I replace "SELECT Count(*)" by "DELETE"
- nierman 4y agoyou can also take advantage of transactions: begin; delete from product where id = 123; --verify things are correct with counts, by issuing "selects", etc. and then issue either a "rollback;" or a "commit;"... I've been happy to have followed this pattern on occasion ;)
- vq 4y agoI always run small mutations like that in a transaction. BEGIN; DELETE FROM product WHERE id=123; ROLLBACK; --COMMIT; And then I remove/comment the ROLLBACK and enable the COMMIT when I'm confident it's correct. This way I also get the number of affected rows for the statement. I do this even on the command line but it's handier in an Emacs buffer and for busy databases you then don't need to worry about other transactions and locking while you type.
- rawoke083600 4y agoLol I like the "amount" of comments (>0) I have on my original-comment, and there I was thinking, I'm the only fool todo deletes/updates via db-console in production :D