4 ms·
When writing and running SQL one-offs interactively, I will surround it with `if 1<>1 begin end` or comments, or add syntax errors at the top so that I won't ac
by Zecc 5y ago
When writing and running SQL one-offs interactively, I will surround it with `if 1<>1 begin end` or comments, or add syntax errors at the top so that I won't accidentally run it without first selecting the part I want to run. I should get into the habit of writing `begin; rollback` instead for extra-safety.
And I always write the WHERE clause before the DELETE or UPDATE keywords.
- chriswarbo 5y ago> And I always write the WHERE clause before the DELETE or UPDATE keywords. I sometimes get nervous typing 'rm -r' commands, since it starts with a very broad path, and only narrows-down as we type more, e.g. if we hit enter prematurely when typing 'rm -r ~/Downloads/archive.zip' we might delete our entire home directory, or all of our downloads. For this reason I often prefix dangerous steps with 'echo'; once I'm confident it's correct, I'll then run the script and double-check that variables/flags/etc. expanded as expected; and only then will I remove the echoes.
- twic 5y agoSimilarly, i sometimes start writing the command line with 'ls' or 'find', and then run it, and once i'm satisfied it describes the right things, i change the find to an rm.
- tux3 5y agoI always write rm <path> -rf for this reason (I was surprised to learn that on some systems, the flags are in a fixed position, at the start!)
- ndsipa_pomu 5y agoOne reason for having the flags before the <path> is so that you can terminate the flags by using '--'. This is especially useful to prevent dubious files being expanded that might start with '-' and be interpreted as flags that leads to unexpected results.
- tux3 5y agoNote that my Debian's `rm` happily supports terminating flags using `--` when necessary, so wanting to support `--` syntax doesn't have to come at the expense of writing -r last. Almost always, if I'm inputting `rm` manually in a shell, I don't need `--`; very few filenames on my disk start with -.
- leghifla 5y agoWhen I was still a student, I accidentally erased all my project source code with: rm * .o I was puzzled by the message ".o: No such file", and then understood why... Now, I always start with ls and if satisfied of the output, replace ls with rm
- contravariant 5y agoQuite a lot of SQL dialects allow the syntax "DELETE * FROM X" for this exact reason, allowing you to more easily change a select statement into a delete.