News for hackers. Stuff that matters.
Re:DELETEs Are Difficult by aurareturn on Monday November 25, 2024 @01:50AM (#42233859)

  DELETE FROM films;
I'm surprised databases makes it so easy to just delete an entire table. I think the command should be

  DELETE FROM films YES-I-KNOW-WHAT-I-AM-DOING;
Re:DELETEs Are Difficult by magicalhippo on Monday November 25, 2024 @02:06AM (#42233920)
Agreed, I've long been thinking that DELETE should require a WHERE clause.

If you really want to just delete everything, just do WHERE 1=1.

Re:DELETEs Are Difficult by buro9 on Sunday December 01, 2024 @02:28AM (#42286853)
UPDATEs should require a WHERE clause too.

At which point we could just say all SQL should have a WHERE clause.

Re:DELETEs Are Difficult by jaredsohn on Sunday December 01, 2024 @02:58AM (#42286970)
I think SELECTs without WHERE clauses are fine
Re:DELETEs Are Difficult by marcosdumay on Sunday December 01, 2024 @09:57AM (#42288737)
But requiring them is fine too. Even more on Postrges, that has booleans.
Re:DELETEs Are Difficult by ahoka on Sunday December 01, 2024 @03:33AM (#42287110)
And queries should start with WHERE.
Re:DELETEs Are Difficult by awestroke on Sunday December 01, 2024 @04:40AM (#42287353)
FROM, then WHERE, then SELECT
Re:DELETEs Are Difficult by Jabbles on Sunday December 01, 2024 @08:02AM (#42288245)
Re:DELETEs Are Difficult by hamandcheese on Sunday December 01, 2024 @05:23AM (#42287538)
This is the way.
Re:DELETEs Are Difficult by yen223 on Sunday December 01, 2024 @05:37AM (#42287593)
It would be nice if there was a psql option that would warn you if you're about to do any kind of update, delete or insert without doing a BEGIN;

(You could always set autocommit=false, which forces you to explicitly commit or rollback every action, but that has its own baggage)

Re:DELETEs Are Difficult by jsemrau on Sunday December 01, 2024 @02:46AM (#42286929)
MySQL has this as default as far as I recall. But then I never delete, I just set "deleted" to yes.
Re:DELETEs Are Difficult by physicsguy on Sunday December 01, 2024 @03:57AM (#42287194)
That just wouldn’t fly where you have business customers, many insist on data deletion at the end of contracts. In practice though partitioning or using seperate databases can be a better strategy for dealing with that as otherwise dealing with backups are challenging.
Re:DELETEs Are Difficult by kijin on Sunday December 01, 2024 @04:27AM (#42287302)
It might depend on the version, but last time I checked, DELETEing an entire table was much slower than TRUNCATE TABLE.
Re:DELETEs Are Difficult by eddd-ddde on Sunday December 01, 2024 @11:42AM (#42289243)
I'm pretty sure that only applies to Postgres.
Re:DELETEs Are Difficult by magicalhippo on Sunday December 01, 2024 @01:06PM (#42289713)
Sybase SQLAnywhere as well, and not unlikely MSSQL too given its shared ancestry.

Delete with WHERE is sufficiently slow in MSSQL we have to do batched deletes, but I can't recall offhand if that holds for whole table deletion as well.

Re:DELETEs Are Difficult by evanelias on Sunday December 01, 2024 @11:54AM (#42289312)
You're probably thinking of the --safe-updates option [1] for the `mysql` CLI, also available as the memorable alias --i-am-a-dummy. This requires UPDATE and DELETE to have either a WHERE clause or a LIMIT clause. Under the hood, the command-line client option just manipulates the sql_safe_updates session variable [2] to enforce the UPDATE and DELETE requirement, as well as a couple other unrelated variables to prevent overly-huge SELECTs.

It's not enabled by default out of the box, but some companies do override their configuration to enable it for new sessions, iirc Facebook did this.

[1] https://dev.mysql.com/doc/refman/8.4/en/mysql-tips.html#safe...

[2] https://dev.mysql.com/doc/refman/8.4/en/server-system-variab...

Re:DELETEs Are Difficult by RedShift1 on Sunday December 01, 2024 @03:16AM (#42287038)
Re:DELETEs Are Difficult by cruffle_duffle on Sunday December 01, 2024 @01:30PM (#42289829)
That is why you always get in the habit of wrapping your stuff in “BEGIN TRANSACTION”. Then if and when you fuck up you can issue a rollback and be all good.
Re:DELETEs Are Difficult by lowbloodsugar on Sunday December 01, 2024 @02:41PM (#42290237)
I’ve deleted the internet??