News for hackers. Stuff that matters.
Re:For Want of a JOIN by jrumbut on Thursday December 22, 2022 @01:10PM (#34096430)
The thing about #2, is poorly designed in comparison to what?

Chances are high the application layer is written in JavaScript, PHP, Ruby, or Python. We don't even talk about nasty edge cases in those languages because they are uncountable.

Re:For Want of a JOIN by jasonhansel on Thursday December 22, 2022 @01:52PM (#34096934)
Those languages all have first-class functions and OOP-style encapsulation.

In SQL stored procedures (at least in Postgres), you can't have a variable that holds multiple records. You can't even define a variable inside of a block.

Re:For Want of a JOIN by ttfkam on Thursday December 22, 2022 @09:44PM (#34101791)
DECLARE foo record[];
Re:For Want of a JOIN by nhinck2 on Friday December 23, 2022 @12:14AM (#34102540)
Temp tables?
Re:For Want of a JOIN by lmm on Thursday December 22, 2022 @06:42PM (#34100508)
None of those languages is as unpleasant as SQL. Not even PHP.
Re:For Want of a JOIN by billythemaniam on Thursday December 22, 2022 @06:54PM (#34100606)
For me, I would much rather SQL especially when using DBT too to manage the queries like any other language. I thought the same way as you and SQL certainly has its warts, but I have grown to appreciate it's elegance. I think over the long-term it is easier to maintain because it is so concise and the most common second language among programmers.
Re:For Want of a JOIN by ttfkam on Thursday December 22, 2022 @09:46PM (#34101802)
Once you start thinking in sets instead of collections of independent statements as per PHP et al, SQL starts looking a lot better.

If you try to fit SQL into the general purpose programming language box, you're gonna have a bad time. A really bad time.

SQL is a DSL for set theory. Nothing more. Nothing less.

Re:For Want of a JOIN by lmm on Thursday December 22, 2022 @10:04PM (#34101919)
The things that are bad about SQL have nothing to do with set theory. The non-orthogonal syntax. The terribly limited and opaque type system. Ternary logic that fails silently. The utter lack of composability or testability.
Re:For Want of a JOIN by ttfkam on Thursday December 22, 2022 @11:06PM (#34102240)
CTEs are quite composable. I might be spoiled by Postgres, but types are quite robust there.

Replace "NULL" with "unknown" in your head, and the ternary makes more sense. When you're building your schema, does an unknown value make sense in that context? Many times not, and the column should either not be nullable or should be referenced in a different table by a foreign key.

3 = NULL

"Is 3 equal to this unknown value?" Maybe yes. Maybe no. It's unknown. Therefore the answer to "3 = NULL" is NULL. The answer is also unknown. Not true. Not false. Unknown.

IS NULL or IS NOT NULL, but never = NULL or <> NULL.

It may be unusual to someone coming from a general purpose programming language's notion of null as a (known) missing value, but that doesn't make it wrong. It means you need to reorient your mind toward set theory, where NULL means "unknown" if you're going to work with SQL and relational databases in general.

Folks often speak of the impedance mismatch between relational models and in-memory object models. NULL is one of those mismatches.

Re:For Want of a JOIN by lmm on Thursday December 22, 2022 @11:13PM (#34102270)
> CTEs are quite composable. I might be spoiled by Postgres, but types are quite robust there.

> Replace "NULL" with "unknown" in your head, and the ternary makes more sense. When you're building your schema, does an unknown value make sense in that context? Many times not, and the column should either not be nullable or should be referenced in a different table by a foreign key.

Cool, now how do I do these two incredibly basic things at the same time and make something not nullable or referencing another table in a CTE?

Re:For Want of a JOIN by fomine3 on Thursday December 22, 2022 @11:51PM (#34102447)
CTEs are quite composable. -- on SQL land.

I wish SQL is more composable

Re:For Want of a JOIN by ttfkam on Friday December 23, 2022 @01:09PM (#34108848)
Also, views are the essence of composability.

As for testing in the Postgres sphere, there's pgTAP and pg_prove. https://pgtap.org/

Extension development includes a built-in unit testing harness as well.

For use with any database, a tool like Sqitch allows for DB-agnostic verification at each migration point. https://sqitch.org/docs/manual/sqitchtutorial/#trust-but-ver...

Proprietary databases have their own solutions as well. https://learn.microsoft.com/en-us/sql/ssdt/walkthrough-creat...

I think "utter lack" is grossly misrepresenting the state of the art. If you mean "widespread ignorance of existing techniques related to composability or testability," then we are in agreement.