Earlier quoted context omitted.
Style opinions are borderline irrelevant without appropriate linters.
Go and use Google BigQuery auto-formatter in a complex query with CASE and EXTRACT YEAR FROM date, and you will have a totally different opinion. How that auto-formatter indents is borderly almost a hate crime. A thousand times better to indent manually.
SQL Anti-Patterns
111–120 of 222 posts
Re: SQL Anti-Patterns
#112Earlier quoted context omitted.
Or, for a boolean type, that XOR is the same as the inequality operator.
Maybe it’s confusing because it’s misnamed?
https://hackage.haskell.org/package/base-4.21.0.0/docs/Data-...
Re: SQL Anti-Patterns
#113Earlier quoted context omitted.
I've been told similar nasty things for adding LIMIT 1 to queries that I expect to return at most a single result, such as querying for an ID. But on large tables (at least in sqlite, mysql, and maybe postgress too) the database will continue to search the entire table after the given record was found.
Only if your table is missing an unique index on that column, which it should have to enforce your assumption, so yeah LIMIT 1 is a code (or schema in the case) smell.
I'll test again, really the last time I tested that was two decades ago.
Re: SQL Anti-Patterns
#114The funny thing is it's actually several of those languages. :-)
Re: SQL Anti-Patterns
#115Earlier quoted context omitted.
Only if your table is missing an unique index on that column, which it should have to enforce your assumption, so yeah LIMIT 1 is a code (or schema in the case) smell.
IDs are typically unique primary key. But in my experience, adding LIMIT 1 would on average halve the time taken to retrieve the record. I'll test again, really the last time I tested that was two decades ago.
I'm curious, can you demo this?
Re: SQL Anti-Patterns
#116was surprised to not see anything about dates/time.
Re: SQL Anti-Patterns
#117Earlier quoted context omitted.
Set theory... There are self-identifying "senior software engineers" that cannot understand what even an XOR is, even after you draw out the entire truth table, all four rows.
I am surprised at common it is for software engineers to not treat booleans properly. I can’t tell you how many times if seen ‘if(IsFoo(X) != false)’ It never used to bug me as a junior dev, but once a peer pointed this out it became impossible for me to ignore.
bool x;
...
if (x == true) {
DoThing1();
} else if (x == false) {
DoThing2();
}
And of course neither branch was hit, because this is C, and the uninitialized x was neither 0 nor 1, but some other random value.Re: SQL Anti-Patterns
#118Earlier quoted context omitted.
Only if your table is missing an unique index on that column, which it should have to enforce your assumption, so yeah LIMIT 1 is a code (or schema in the case) smell.
IDs are typically unique primary key. But in my experience, adding LIMIT 1 would on average halve the time taken to retrieve the record. I'll test again, really the last time I tested that was two decades ago.
Do you recall what the database server was?
Re: SQL Anti-Patterns
#119Re: SQL Anti-Patterns
#120"Instead you should: query WHERE name = ‘abc’ create an indexed UPPER(name) column" Should there be an "or" between these 2 points, or am I missing something? Why create an UPPER index column and not use it?