Live data from Hacker News

An UPDATE without a WHERE, or something close to it

rachelbythebay.com

41–50 of 112 posts

Re: An UPDATE without a WHERE, or something close to it

#45
post #44
post #43

Surely this will become a non-problem as we migrate to NOSQL... no...? oh? we're migrating back? great.

This is not about SQL; it's about user interfaces. The author is only using SQL as an explanatory tool.

sorry, the UK sarcasm mark-down doesn't always render correctly...

Re: An UPDATE without a WHERE, or something close to it

#47
post #16

A particularly nasty aspect of SQL UPDATE syntax is the predicate order, i.e. SET is before WHERE. So when you type it in order, there's a dangerous phase you have to go through if you hit enter by accident. Having run an `mkfs.ext3 /dev/sda` (note the missing partition number) by accident, I've learned to start potentially destructive commands by typing first whatever makes that command a comment (# in shell, -- in…

> A particularly nasty aspect of SQL UPDATE syntax is the predicate order, i.e. SET is before WHERE. So when you type it in order, there's a dangerous phase you have to go through if you hit enter by accident.

I religiously write it out of order for this reason. The IDE complains for a bit, but it's better to deal with some squiggles for a few seconds until you've filled in the column assignments part.

Re: An UPDATE without a WHERE, or something close to it

#48
post #16

A particularly nasty aspect of SQL UPDATE syntax is the predicate order, i.e. SET is before WHERE. So when you type it in order, there's a dangerous phase you have to go through if you hit enter by accident. Having run an `mkfs.ext3 /dev/sda` (note the missing partition number) by accident, I've learned to start potentially destructive commands by typing first whatever makes that command a comment (# in shell, -- in…

Predicate order in SQL is pretty dodgy all around and makes it hard to build intuition around SQL queries. In select, the actual SELECT clause (field selection) can usually be conceptualized as “happening” after all other clauses, but of course it comes first in the query.

This problem is fixed in query languages like EdgeQL.[0]

[0] https://www.edgedb.com/docs/edgeql/commands/update

Re: An UPDATE without a WHERE, or something close to it

#49
post #16

A particularly nasty aspect of SQL UPDATE syntax is the predicate order, i.e. SET is before WHERE. So when you type it in order, there's a dangerous phase you have to go through if you hit enter by accident. Having run an `mkfs.ext3 /dev/sda` (note the missing partition number) by accident, I've learned to start potentially destructive commands by typing first whatever makes that command a comment (# in shell, -- in…

One quick trick I use a lot in the shell is to run a known safe command with the argument first, and then run the dangerous command with the the !$ variable (the last argument of the previous command) so there's no possibility of a mistake in copying and pasting. Something like: `ls /tmp/junk; rm !$`.

I think !$ takes the last argument on the previous command in history, not previous one on the same line.. at least in bash. For example, if you do:

  $ ls /
  $ ls /tmp/junk; rm !$
It's taking "/" rather than "/tmp/junk"..

EDIT: formatting

Post reply on HN