News for hackers. Stuff that matters.
Re:$ rm Important.txt (uh oh) by rawoke083600 on Sunday September 18, 2022 @01:59AM (#32884820)
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.

Re:$ rm Important.txt (uh oh) by vq on Sunday September 18, 2022 @03:09AM (#32885208)
I 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.

Re:$ rm Important.txt (uh oh) by iforgotpassword on Sunday September 18, 2022 @02:44AM (#32885058)
I write them as

  SELECT Count(*) FROM product WHERE id = 123
And if the number looks right I replace "SELECT Count(*)" by "DELETE"
Re:$ rm Important.txt (uh oh) by nierman on Sunday September 18, 2022 @02:56AM (#32885128)
you 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 ;)
Re:$ rm Important.txt (uh oh) by rawoke083600 on Sunday September 18, 2022 @04:28AM (#32885592)
Lol 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