News for hackers. Stuff that matters.
Re:We Can Do Better Than SQL by tqi on Tuesday August 11, 2020 @01:43AM (#24117492)
It's pretty arrogant to complain about the syntax being inconsistent across versions and databases and then present your own weird offshoot, as if every other version wasn't introduced for the exact same reason with the exact same lofty delusions of grandeur...

SQL is messy because describing the underlying data relationships are messy. The orthogonality example is a great illustration of this. What exactly should the result be if there are multiple dept heads? Should the result rows be duplicated? It's not clear how edgeQl would handle either (their edgQl orthogonality examples were constructed to only have result per sub query), but it seems like they would be kept together as sets. In that case, the result set is no longer a table, it's a dataframe, which is a useful data structure but is also not what relational databases do.

Re:We Can Do Better Than SQL by roenxi on Tuesday August 11, 2020 @04:51AM (#24118468)
> SQL is messy because describing the underlying data relationships are messy.

> SELECT extract(day from timestamp '2001-02-16 20:38:40');

SQL is messy because all the syntax was decided on before there was a community that really understood what good syntax is. The 'from' in that extract does nothing and I can't easily identify if extract is a function or some sort of crazy parsing construct - what are the arguments? Is "day from timestamp '2001-02-16 20:38:40'" the argument? Are the arguments "day", "timestamp" and "'2001-02-16 20:38:40'"?

Are these annoyances crippling? Yes. Yes they are crippling. It should be possible for an amateur to quickly write an SQL validator as a starting project; relational algebra is not complicated. Any fool can write a validator for lisp. Relational algebra isn't that much more complicated - we don't have loops or flow control to contend with here.

Tidyverse's dplyr [0] implements the relational model for real dirty data and, as might be expected for something implemented this century, does a much better job than SQL. Not because the operations are that much different (although gather() & spread() are welcome additions) but through ingenious innovations like, as mentioned, functions having arguments instead of I-don't-even-know-what-that-is.

And the pipe operator which is legitimately ingenious. Great operator for data.

[0] https://dplyr.tidyverse.org/reference/index.html

Re:We Can Do Better Than SQL by sanderjd on Tuesday August 11, 2020 @08:54AM (#24119768)
> It should be possible for an amateur to quickly write an SQL validator as a starting project

...why? SQL has been wildly paradigm-definingly useful for decades. It has driven hundreds of billions, perhaps trillions, of dollars of value. None of this hinges on the ability for an amateur to be able to write a validator for the language. It just seems like such a non-sequitur to me, such a strange thing to call out as a criticism.

SQL hasn't been wildly successful either because of or despite its syntax, it has been wildly successful because organizing data in the relational model and querying it declaratively is extremely powerful. The syntax is just not the interesting part. Any syntax that meets those criteria would do.

Re:We Can Do Better Than SQL by hospadar on Tuesday August 11, 2020 @09:56AM (#24120256)
I second this emotion SO HARD. Is sql weird? sure. But (IMO) the hard part implementing|using a sql database is _not_ the syntax, it's the storage, query planning, consistency. Don't like SQL? use linq or one of the bazillion DSL libraries that "compile" to sql. SQL databases are so unbelievably extremely useful, and the minor syntax quirks between different DBs are a minor issue compared to the huge amount of commonality that they share.

Also FWIW, I'm not sure that writing a sql validator _is_ all that hard. The grammars for any dialect are readily available and really not so hard to turn into an AST with any of your favorite tools (ANTLR, lex/yacc/bison, any of a million PEG parser generators). In many cases you don't even need to, we do static analysis of spark SQL using their own parser, for postgres can use the parser straight out of libpg.

I guess the OPs point is that if you can validate it easily, you can understand it. I'm certain I could write a lisp parser in 10 minutes, but I don't think that would mean I immediately understand all Clojure code (which is often pretty obtuse). You still need to learn all the underlying concepts and data structures.

Re:We Can Do Better Than SQL by Certhas on Tuesday August 11, 2020 @10:00AM (#24120308)
Your last paragraph is non sequitur. It is perfectly possible for the syntax to not be the interesting part, and for SQL to have been successful despite bad syntax. The underlying idea is brilliant, so the first syntax that exposed it sufficiently well got baked in as a path dependency, even though the syntax sucks.
Re:We Can Do Better Than SQL by sanderjd on Tuesday August 11, 2020 @11:00AM (#24120987)
The point I was trying to make was just that the syntax was irrelevant; it was neither a major advantage nor hindrance. I think this is the same as your point.
Re:We Can Do Better Than SQL by Threeve303 on Tuesday August 11, 2020 @11:36AM (#24121475)
One thing I have experienced is that often times developers are coming from a world of object oriented programming, or just coming from a JavaScript world.

Then often the storage and retrieval of data is an after thought during the development of an application. This is definitely true for CRUD apps. Then maybe the person used a framework to handle database interactions and now after a year or so, it’s not scaling well because the data access was not really given priority during development. So then the problem is the database engine or the syntax instead of proper design and planning.

That’s not to say there are no drawbacks to writing most dialects of SQL. I just believe most of the hate over SQL is coming from a procedural mindset to a relational one.

Re:We Can Do Better Than SQL by mufufu on Tuesday August 11, 2020 @09:35AM (#24120105)
> It should be possible for an amateur to quickly write an SQL validator as a starting project

I think the point he is trying to make here is the same as the post was making concerning orthogonality. Having a smaller set of special syntax, and therefore an easier validator to write, means easier queries to write for the user. I don’t think he was implying that everyone who makes use of the language should know how to write a lexer for it.

> The syntax is just not the interesting part. Any syntax that meets those criteria would do.

I have to disagree with this. If this was the case we would still be programming everything in BASIC or C because they’re just another imperative programming language and it gets the job done. Having sugar syntax, a consistent language, etc.. all makes it easier for a programmer (or data analyst) to get the job he needs quicker (and therefore reduces cost), makes a program easier to maintain, and so on.

Re:We Can Do Better Than SQL by sanderjd on Tuesday August 11, 2020 @10:58AM (#24120949)
The syntax is not the interesting part for programming languages either. Programming languages now have better semantics - things like runtimes, concurrency, data encapsulation, etc. - in addition to better syntax. SQL is not a programming language, its semantics boil down to the relational model. Don't get me wrong, there is room for improvement in the syntax, I have plenty of gripes with it, I just don't agree that it is a fundamental problem. It's already super useful as it is.
Re:We Can Do Better Than SQL by Risord on Tuesday August 11, 2020 @01:24PM (#24122949)
Indeed semantics is what matter but I think for example lack of composability is semantic problem too.

<snarky> Ability to manage persistency and correctness of SQL engines is very usefull while language interface not so much. </snarky>

Re:We Can Do Better Than SQL by 0fcf8d3559a64c on Tuesday August 11, 2020 @12:02PM (#24121858)
>It has driven hundreds of billions, perhaps trillions, of dollars of value.

The same can (almost) be said for Javascript. A language with a lot of foibles can still be successful if it is the only realistic mechanism to interact with the system.

Re:We Can Do Better Than SQL by sanderjd on Tuesday August 11, 2020 @08:58PM (#24127624)
No disagreement from me there! Though I personally like SQL more :)
Re:We Can Do Better Than SQL by mannykannot on Tuesday August 11, 2020 @10:33AM (#24120659)
>> It should be possible for an amateur to quickly write an SQL validator as a starting project

> ...why?

I don't know about amateurs, but if the typical intended user of the language does not have a good grasp of what is and is not valid, they will often be reduced to trying one thing after another until they hit upon something that seems to work, with no real understanding of what it does. This is not how robust, correct software is written.

Re:We Can Do Better Than SQL by sanderjd on Tuesday August 11, 2020 @10:50AM (#24120851)
That seems like a completely different point. (Unless I misunderstand what a "SQL validator" is, which is definitely possible.)

I do think this way of utilizing SQL is a problem, but I would lay the blame for it at the feet of a lamentably widespread anti-intellectualism in the field. It is true that the relational model is not trivial and must be learned before SQL makes much sense. But it is not too much to expect from someone who wants to be a practitioner in this field.

Re:We Can Do Better Than SQL by mannykannot on Tuesday August 11, 2020 @11:23AM (#24121263)
I agree that someone who wants to be a practitioner in this field should understand the relational model, but the issue here is that SQL introduces inconsistencies and complications that are not inherent in the relational model, and, to some extent are avoidable. A justifiable emphasis on professionalism does not absolve SQL of these faults and does not render irrelevant attempts to find better language choices.
Re:We Can Do Better Than SQL by sanderjd on Tuesday August 11, 2020 @10:24PM (#24128023)
Sure, I don't disagree. My point is that the perfect is the enemy of the good, and SQL is the good.
Re:We Can Do Better Than SQL by krick on Tuesday August 11, 2020 @06:29AM (#24118926)
> all the syntax decided on before there was a community that really understood what good syntax is

Here you got me thinking: do we even understand that now? There was quite a bit of contemplating about of semantics, data types and different kinds of abstractions in the programming languages for the last couple of generations already, but the general consensus about the syntax is that "nice syntax is nice, but it isn't really that important". Most modern languages loosely follow either something C-like or Algol-like, most people like what they are familiar with. There are sometimes claims that a good syntax should be successfully parsed by some relatively simple parser (which is totally not obvious, TBH, because while it is clear why C++ is a good counter-example, we don't really have that many good examples: classic LR-parsers or something like that are really not that powerful, and most real-world programming languages implement something very non-generic of their own). Some people claim that "good syntax is no syntax" (Lisp), and some say that Haskell has a good syntax (ikr). The bottom line being that this is just a matter of taste, unlike most of what we can say about types and data structures.

So, to summarize: I never actually heard a compelling general theory of good syntax.

This is completely offtopic, BTW, I agree that SQL is trash and it is even kinda funny that somebody tries to defend it like that, since for a long time it was sort of a textbook example of "why a language created with the idea to be used by non-technical people is a failure from the very beginning".

Re:We Can Do Better Than SQL by kd5bjo on Tuesday August 11, 2020 @06:43AM (#24118993)
> So, to summarize: I never actually heard a compelling general theory of good syntax.

I started to think along these lines when I got serious about learning a foreign language. Humans appear to have some innate language ability that’s reflected, among other things, in commonalities between disparate languages. As far as I can tell, there’s been no serious effort to design a computer language to take advantage of this.

My pet theory about why the object.method(args) call syntax won is that it really is the most natural to read, as evidenced by the fact that most human languages follow subject-verb-object word order.

Re:We Can Do Better Than SQL by feikname on Tuesday August 11, 2020 @08:40AM (#24119656)
> My pet theory about why the object.method(args) call syntax won is that it really is the most natural to read, as evidenced by the fact that most human languages follow subject-verb-object word order.

Most western languages maybe, but according to wikipedia[1] the most common is actually SOV rather than SVO.

[1] https://en.wikipedia.org/wiki/Word_order#Distribution_of_wor...

Re:We Can Do Better Than SQL by indecisive_user on Tuesday August 11, 2020 @10:52AM (#24120869)
Most common by number of languages maybe, but if we look at most common by number of people who speak the language, the top 3 most popular languages in the world(Mandarin, Spanish, English) are all SVO.
Re:We Can Do Better Than SQL by lifthrasiir on Tuesday August 11, 2020 @08:45AM (#24119695)
> [...] as evidenced by the fact that most human languages follow subject-verb-object word order.

Nope. [1]

[1] https://wals.info/chapter/81 (Note that while this is the language count only, the same comment applies to the population using such word order as a native tongue: SOV and SVO are both common.)

Re:We Can Do Better Than SQL by g5becks on Tuesday August 11, 2020 @08:29AM (#24119592)
Though I program in languages that most follow the obj.method(args) pattern, I really prefer the args |> function |> function pattern and I wish it was the norm in every programming language.
Re:We Can Do Better Than SQL by dahfizz on Tuesday August 11, 2020 @09:07AM (#24119885)
In what language is that used? It reminds me of pipes in bash. I can see it being useful in circumstances where you have lots of function calls and fewer arguments (just like pipes), but I think it would look really ugly and hard to parse with a long arg list.
Re:We Can Do Better Than SQL by jdmichal on Tuesday August 11, 2020 @09:29AM (#24120064)
It's a common functional thing. I know F# has both `|>` and `<|` to go both directions. It also has `||>` and `|||>` variants which take two- or three-value tuples and spread them to arguments.

https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...

Re:We Can Do Better Than SQL by paublyrne on Tuesday August 11, 2020 @09:24AM (#24120026)
Elixir for one.

Yes it works best when you have one argument to pass, as the first argument is passed implicitly.

https://hexdocs.pm/elixir/Kernel.html#%7C%3E/2

Re:We Can Do Better Than SQL by Certhas on Tuesday August 11, 2020 @10:06AM (#24120364)
Re:We Can Do Better Than SQL by phaedryx on Tuesday August 11, 2020 @10:05AM (#24120352)
See also Clojure's threading macros: https://clojure.org/guides/threading_macros
Re:We Can Do Better Than SQL by int_19h on Tuesday August 11, 2020 @11:40PM (#24128398)
These are two different use cases. In the first case, which method the call actually dispatches to depends on obj, so it kinda makes sense for it to be syntactically distinct from other args. The pipeline syntax is normally used with free-standing functions that are statically dispatched.

Now, yes, there are languages with multimethods, where the distinction is less obvious. For those that always dispatch on all arguments, a uniform syntax makes more sense. CLOS is a good example.

Re:We Can Do Better Than SQL by ukj on Tuesday August 11, 2020 @07:05AM (#24119100)
The commonality you are referring to sounds like Chomsky's concept of Universal Grammar [1].

The object.method(args) "won" because it is a low barrier to entry from English to Programming indeed, but as you become more and more experienced and you shake off the imperative way of thinking in favour of declarative thinking functional languages becomes more expressive than imperative languages. They become better at managing complexity because they allow you to build higher and higher towers of abstraction.

And then homoiconicity [2] shines because of its 'universally grammatic' property.

1. https://en.wikipedia.org/wiki/Universal_grammar

2. https://en.wikipedia.org/wiki/Homoiconicity

Re:We Can Do Better Than SQL by kd5bjo on Tuesday August 11, 2020 @07:58AM (#24119396)
I was thinking on a more basic level than UG; just the presence of linguistic universals [1]. I agree that functional languages are in a certain way more expressive than imperative ones, but that seems mostly orthogonal to the syntax of the language.

I’m thinking about basic stuff like improper nouns, denoting a clause’s role by inflection or adposition instead of word order, and having a clearly defined spoken representation- none of this is specific to which abstract structures the language is describing.

https://en.wikipedia.org/wiki/Linguistic_universal

Re:We Can Do Better Than SQL by yyyk on Tuesday August 11, 2020 @09:41AM (#24120139)
>The object.method(args) "won" because it is a low barrier to entry from English to Programming indeed

BASIC and C didn't have a concept of objects* , which didn't seem to hinder adoption at all. object.method() became popular when OOP languages became popular, and that was because IDEs offered better autocompletion with that syntax.

* We could emulate objects with C in some gnarly ways. Almost no one did at the time, excluding C-with-classes/C++.

Re:We Can Do Better Than SQL by skocznymroczny on Tuesday August 11, 2020 @08:06AM (#24119448)
It's not that simple, D has UFCS (Uniform Function Call Syntax), which makes object.method(args) and method(object, args) equivalent calls.

Also there's a non-language related advantage of dot notation. Type the name of the object, press dot and IDE will show you what things you can do with that object. You don't have that with other notations.

Re:We Can Do Better Than SQL by jasonpbecker on Tuesday August 11, 2020 @08:17AM (#24119503)
That assumes a very OO mindset. method(object, args)/function(data, parameters) works better in other languages, and IDEs can handle this quite well without dot syntax.

Which goes to your point-- form follows function, in syntax as with many other things.

Re:We Can Do Better Than SQL by gvjddbnvdrbv on Tuesday August 11, 2020 @08:09AM (#24119455)
Why is dot special? Fortran uses % (if I remember properly) IDE's can complete after a % as well as after a dot.
Re:We Can Do Better Than SQL by int_19h on Tuesday August 11, 2020 @11:42PM (#24128410)
Dot is not special. Putting the receiver objects first is special, because it allows the IDE to only show verbs (methods) that pertain to that object. If you put the verb first, code completion lacks context, so it would necessarily have to show you all verbs that can apply to any object that could conceivably be acted on in that scope.
Re:We Can Do Better Than SQL by int_19h on Tuesday August 11, 2020 @11:50PM (#24128440)
> SQL is messy because all the syntax was decided on before there was a community that really understood what good syntax is.

It's not that they didn't understand it. There are languages predating SQL that have better syntax.

But SQL was one of the so-called "4th generation programming languages", that were supposed to be operating at a much higher level. And because of that, there was the notion that, if they also have a more "natural" syntax, it would allow people who are not programmers to use them effectively. Hence why SQL was originally SEQUEL - Structured English Query Language. It was meant to be written by domain experts, not database experts.

Of course, that failed (like countless other similar attempts since then), and so now we're stuck with this syntax for no good reason whatsoever.

Re:We Can Do Better Than SQL by ideamotor on Tuesday August 11, 2020 @05:33AM (#24118672)
Please use pivot_wider and pivot_longer instead of gather and spread. The true horror, even admitted by the the dplyr team ...
Re:We Can Do Better Than SQL by roenxi on Tuesday August 11, 2020 @05:47AM (#24118726)
Oh, they're new. Great. Thanks for the tip.
Re:We Can Do Better Than SQL by klmr on Tuesday August 11, 2020 @06:29AM (#24118927)
As a point of minor historic curiosity, the pipe operator in R actually predates dplyr and was invented independently multiple times by various people who noticed that the Unix model translates well to data transformations in R (F# also has a pipe but I'm not aware of anybody using F# as an inspiration for the pipe in R).
Re:We Can Do Better Than SQL by thom on Tuesday August 11, 2020 @08:22AM (#24119538)
Except that dplyr is horribly slow and memory inefficient, and (if you were minded to actually put R code into production) it more or less forces you to do data prep in a database anyway.
Re:We Can Do Better Than SQL by goto11 on Tuesday August 11, 2020 @08:59AM (#24119804)
> SQL is messy because describing the underlying data relationships are messy.

No, the relational model is beautiful and consistent! SQL is messy because the syntax is not consistent and elegantly composable. It could have those properties and still present the same underlying data relationships.

See Linq in C# as an example for how a more composable query syntax can expose the same data model.

For example in Linq you can chain arbitrary many select/join/where/group by in arbitrary order. In SQL you need nested subqueries to achieve the same which is a much more convoluted syntax.

Re:We Can Do Better Than SQL by gboss on Tuesday August 11, 2020 @09:19AM (#24119984)
Slightly tangential but I really like Linq syntax. The only problem I have with it is that it is really hard to debug if there is a logic error. I often see developers write linq find out the record set they get back is incorrect and then break up the linq query to a nested if clause to get what they want.
Re:We Can Do Better Than SQL by merb on Tuesday August 11, 2020 @05:08PM (#24125996)
I've seen so many errors around orderby/limit. which most people want at the end, but linq lets them define it, everywhere. (for a good reason) but this is probably the biggest problem with linq, it's a chain of operators that are ORDER dependant!!
Re:We Can Do Better Than SQL by int_19h on Tuesday August 11, 2020 @11:25PM (#24128335)
That's a quality of tooling issue. And in Visual Studio, for example, you can set breakpoints on individual subexpressions in the query.
Re:We Can Do Better Than SQL by nightski on Tuesday August 11, 2020 @12:11PM (#24121977)
Yeah I feel like that happens whenever you have a mapping from one language to another. Eventually you learn the intricacies of the transformation. There are very few situations where the Linq I write does not translate into the query I expect any more. But that took time to learn.

The only criticism I have of Linq is that it is a more general language targeting different back-ends including plain old objects. If Linq did not allow things that do not make sense in SQL this would be a little less jarring.

I also wish it supported full outer joins, unions, and window functions.

Re:We Can Do Better Than SQL by scarface74 on Wednesday August 12, 2020 @11:11AM (#24132825)
I was amazed the first time I used the MongoLinq driver. It makes sense intuitively, but the idea that you can use the same Linq expression and it will be translated to either Sql or MongoQuery based on the provider you send it to was amazing.

I was able to hire a four or five contractors who never used Mongo just by requiring Entity Framework/Linq experience and less than 4 hours of training.

Re:We Can Do Better Than SQL by marcinzm on Tuesday August 11, 2020 @09:38AM (#24120124)
>For example in Linq you can chain arbitrary many select/join/where/group by in arbitrary order. In SQL you need nested subqueries to achieve the same which is a much more convoluted syntax.

WITH statements alleviate some of this issue by allowing you to write subqueries in any order.

Re:We Can Do Better Than SQL by jimsparkman on Tuesday August 11, 2020 @09:43AM (#24120152)
WITH (CTEs) make queries so much more readable and digestible. As a programmer who now does data and SQL, I latched on to these as soon as I found I could reduce repetition in a query with them.
Re:We Can Do Better Than SQL by meritt on Tuesday August 11, 2020 @11:28AM (#24121351)
Make sure you understand what optimization fences are and how they affect your performance. CTEs are nice to read but routinely destroy the performance.

[1] https://thoughtbot.com/blog/advanced-postgres-performance-ti...

Re:We Can Do Better Than SQL by bjt on Tuesday August 11, 2020 @11:45AM (#24121585)
As of Postgres 12 this has changed substantially. Instead of being materialized, CTEs are inlined and optimized with the rest of the query.

Exceptions:

1. If the results of the CTE are used more than once then it is materialized by default, though you can override this by adding "NOT MATERIALIZED" to the call.

2. Recursive and INSERT/UPDATE/DELETE CTEs are always materialized.

https://paquier.xyz/postgresql-2/postgres-12-with-materializ...

Re:We Can Do Better Than SQL by oarabbus_ on Tuesday August 11, 2020 @01:33PM (#24123086)
>CTEs are nice to read but routinely destroy the performance.

This may be true on archaic versions of MySQL and Postgres but is not the case today, barring some esoteric edge cases (bugs) where the optimizer gets thrown out of whack. Once while doing data science consulting I rewrote a ~1000 line query in Aurora (MySQL flavored) which had a ~2.5s runtime, which was far too slow for the client's use-case.

After rewriting all the CTEs (there were many) into subqueries, there was a 2-3% increase in query speed, barely (on the order of under a tenth of a second). There was a very tiny improvement far smaller than the normal variance of the runtime.

Then I rebuilt the query and the joins, and was able to get the query to consistently run in the range of 0.8 - 1.2s. For my own purposes I then duplicated the query, re-implemented the CTEs, and did validate that indeed there is only a negligible increase in query time when using CTE.

Re:We Can Do Better Than SQL by 3pt14159 on Tuesday August 11, 2020 @10:10AM (#24120392)
For monster queries (thousands of lines of SQL) I find that temporary tables are also great. You can index them and, depending on your DB and its settings, they're usually held in RAM so they're super fast.
Re:We Can Do Better Than SQL by sumtechguy on Tuesday August 11, 2020 @10:40AM (#24120728)
That is implementation specific. In some db's putting an index on a temp table does nothing. In later versions of the same db it does but only in particular cases. Make sure you read the docs around that.
Re:We Can Do Better Than SQL by achr2 on Tuesday August 11, 2020 @10:26AM (#24120568)
CTEs do not get cached though, so they are actually quite bad for repetition without also using a temp table.
Re:We Can Do Better Than SQL by ComodoHacker on Wednesday August 12, 2020 @07:31AM (#24130918)
Depends on DBMS and version. Some are smart enough to pipeline/tie or materialize it internally.
Re:We Can Do Better Than SQL by pmarreck on Tuesday August 11, 2020 @10:20AM (#24120501)
Ecto.Query in the Elixir universe seems like it was inspired by linq
Re:We Can Do Better Than SQL by goto11 on Tuesday August 11, 2020 @02:18PM (#24123738)
WITH's are great and definitely solves some of the issues with SQL. Some implementations unfortunately don't optimize them as subqueries, but that is not the fault of SQL.
Re:We Can Do Better Than SQL by prostodata on Tuesday August 11, 2020 @12:09PM (#24121948)
> No, the relational model is beautiful and consistent! SQL is messy...

What is beautiful and consistent is the relational algebra. The relation model relies on this formalism to model data by making some rather strong assumptions about how tuples and relations represent things and how relational operations are used to process them. And these assumptions are precisely what propagates to SQL and what some authors (see references in the article) consider controversial and messy. Then the question is whether and how these controversies can be fixed (or whether they are bugs or features).

A radically different approach to fix these controversies is to introduce a different formalism and different data model (as opposed to fixing only syntax) which is based on using functions. In other words, instead of using sets and set operations, we use in addition functions and function operations [1]. Here you can find an implementation of this approach:

https://github.com/prostodata/prosto Prosto is a data processing toolkit radically changing how data is processed by using both sets and functions and being a major alternative to map-reduce, join-groupby and other set-oriented approaches

[1] Concept-oriented model: Modeling and processing data using functions: https://www.researchgate.net/publication/337336089_Concept-o... -> Read introduction (two pages) for why having only sets is not enough and why functions are important

Re:We Can Do Better Than SQL by achr2 on Tuesday August 11, 2020 @10:32AM (#24120644)
I disagree, the relational model is very incongruous with the object model that nearly all LOB applications use. Which is where 99% of the usage issues lie.
Re:We Can Do Better Than SQL by wtetzner on Tuesday August 11, 2020 @12:09PM (#24121959)
That doesn't make the relation model bad, it just means there's an impedance mismatch.

FWIW, I find the relational model to be much nicer than typical object models. Even in Java, which I write every day at work, I've found it to be much clearer to use immutable objects representing records. Not just for interacting with the database, but just for handling information in general.

Of course, it would be extremely painful to do without Lombok's @Value, @Builder, and @With annotations.

Re:We Can Do Better Than SQL by achr2 on Tuesday August 11, 2020 @01:18PM (#24122860)
I agree that the mismatch is not a direct failing of SQL or the relational model - but we continue to use it without adopting a better approach or developing a common abstraction layer. With all of the syntax growth, SQL could certainly have a join syntax that understands object composition and returns structured data.
Re:We Can Do Better Than SQL by wtetzner on Thursday August 13, 2020 @02:17PM (#24146391)
> With all of the syntax growth, SQL could certainly have a join syntax that understands object composition and returns structured data.

I mean, many RDBMS's have support for JSON and/or XML, so you can sort of get it.

However, I wonder if we'd be better of as an industry if we dealt with our data in code in a more relation-y way than an object-y way.

Re:We Can Do Better Than SQL by nine_k on Tuesday August 11, 2020 @04:42PM (#24125737)
It's the problem with the object model. Yes, I think ORMs are an anti-pattern, ActiveRecord-style especially.
Re:We Can Do Better Than SQL by scarface74 on Wednesday August 12, 2020 @11:16AM (#24132875)
And then you end up inventing your own ORM and “helpers” because eventually the results end up in objects.

I do hate most ORMs. The only oneS I like are Linq based ORMs. The “ORM” is actually well integrated into the language.

You might as well use something like Dapper.

But yes agreed about ActiveRecord.

Re:We Can Do Better Than SQL by mannykannot on Tuesday August 11, 2020 @10:40AM (#24120716)
You have piqued my curiosity, but what would a linq solution to this exercise look like?
Re:We Can Do Better Than SQL by int_19h on Tuesday August 11, 2020 @11:29PM (#24128356)
Which particular exercise?
Re:We Can Do Better Than SQL by mannykannot on Wednesday August 12, 2020 @07:35PM (#24138349)
The multiple dept. heads case.
Re:We Can Do Better Than SQL by 013a on Tuesday August 11, 2020 @10:23AM (#24120536)
A very simple, basic SQL query would be something like "select * from users where foo=bar;"

Already, we're introducing a weird inversion of syntax that, in my experience, trips up people learning it: data in SQL is stored as "rows" with "columns" inside "tables". More formally, we've got a hierarchical relationship where Tables > Rows > Columns, yet we write the query as Columns > Table > Rows.

There are far more consistent and beautiful querying languages than SQL: I would point to MongoDB's query language, which is less of a query language and more of a static javascript-interpretable library, but is still far easier to learn and more consistent than SQL. The same query in MongoDB: "db.users.find({ foo: "bar" });". How is this better? It embeds the operation in the statement ("find"); reading it hierarchically follows how the data is stored (Collection > Rows); the filtering operation is the same shape as the data being stored; and it naturally disallows most injection attacks.

Re:We Can Do Better Than SQL by guiriduro on Tuesday August 11, 2020 @11:06AM (#24121059)
I always thought a SQL query has a very sensible layout, I was never confused as to which I was doing or in what order. For me a query can be simplified to: select <projection> <selection>
Re:We Can Do Better Than SQL by njharman on Tuesday August 11, 2020 @12:12PM (#24121990)
> db.users.find({ foo: "bar" })

I don't know MongoDB query language, but gah! that looks horrible. It uses three different syntaxes; dot notation, curlies/brackets and colon key value. Full of punctuation and doesn't read like english.

There is no distinction between noun "users" and verb "find". There's extraneous "db". does foo: "bar" mean equal or is it find() that determines the operator, maybe combo of both? how do I do other operations.

.Only if you are familiar with programing language that has that same syntax does any of it make sense. Otoh even educated non-programmers are gonna be able to read the SQL as SELECT "these things" FROM "this table" WHERE "these conditions are true".

Re:We Can Do Better Than SQL by doubletgl on Tuesday August 11, 2020 @12:23PM (#24122121)
> Only if you are familiar with programing language that has that same syntax does any of it make sense.

I'd argue that most relational DB users are familiar with a programming language, and therefore most likely familiar with the C-style syntax. It's better to build on something that most of the potentials users are familiar with already.

> There is no distinction between noun "users" and verb "find".

There is no such distinction in natural language either (if you see words purely as sequences of characters), you have to know what is what and infer it from the context.

> even educated non-programmers are gonna be able to read the SQL as SELECT "these things" FROM "this table" WHERE "these conditions are true".

Yeah SQL looks a bit more like natural language at first glance, but that's about it. That familiarity is a false friend, it doesn't really help with the learning curve.

This kind of thinking reminds me of the ruby community trend a decade ago when DSLs were created to look beautiful and like written language. It's useless and confusing for long-term, practical purposes. Same with BDD style testing languages. The promise that non-technical people will feel right at home and can start contributing rarely lives up to reality.

Re:We Can Do Better Than SQL by fomine3 on Friday August 14, 2020 @03:51AM (#24155064)
> It uses three different syntaxes; dot notation, curlies/brackets and colon key value.

Is it an issue? using symbols makes it easier to understand syntax.

> There is no distinction between noun "users" and verb "find".

Weird criticism from SQL. It can be distinguish by call with parenthesis.

IMO SQL keyword is harder to recognize.

Re:We Can Do Better Than SQL by 013a on Tuesday August 11, 2020 @01:42PM (#24123258)
Why would you want your query language to read like English? Most people don't speak English.
Re:We Can Do Better Than SQL by jolux on Tuesday August 11, 2020 @10:30AM (#24120628)
That doesn’t prevent injection, and the solution to injection attacks is using parameterized queries and prepared statements, not switching to MongoDB. Plus ORMs (really query builders) already provide behavior like this against SQL databases anyway.
Re:We Can Do Better Than SQL by 013a on Tuesday August 11, 2020 @02:06PM (#24123590)
That's fair, but I didn't say it prevents injection: I said it prevents most injection attacks.

MongoDB is absolutely still capable of being vulnerable to injection; its just harder, because it requires the client to provide an object which is parsed by your application with no data validation. In other words, SQL is vulnerable to injection by-default, because everything is a string, while you have to opt-in to being vulnerable with MongoDB, by writing your application to parse user input with no schema.

In reality, do applications do this? Hell yeah. Wire up a basic Express API, have it auto-parse any JSON its given, pass it straight to mongo, you'll be vulnerable. But, a backend which has any kind of type safety or API schema or GraphQL or something like that will be safer on mongodb than one with all that, on a SQL database with no ORM or parameterized queries or prepared statements.

Re:We Can Do Better Than SQL by jolux on Tuesday August 11, 2020 @08:00PM (#24127321)
The difference as minimal. If you know the first thing about what you're doing with SQL you will use prepared statements. It's not some sort of arcane feature that nobody understands.
Re:We Can Do Better Than SQL by throwaway894345 on Tuesday August 11, 2020 @10:46AM (#24120790)
And those ORMs have to deal with the SQL composability issues as well, often to the effect of dramatically poorer performance.
Re:We Can Do Better Than SQL by jolux on Tuesday August 11, 2020 @11:05AM (#24121045)
You’re right, using a query layer to access an SQL database is still using an SQL database. You need to know what you’re doing with your queries. The important part is not the object mapping and model tracking part, it’s the part that allows you to build typed queries in the native language. Diesel for Rust is a great example, as is Ecto in Elixir.
Re:We Can Do Better Than SQL by romanoderoma on Tuesday August 11, 2020 @11:03AM (#24121024)
I think Elixir ECTO does a very good job at that

https://hexdocs.pm/ecto/Ecto.Query.html#module-composition

Re:We Can Do Better Than SQL by lostjohnny on Tuesday August 11, 2020 @10:55AM (#24120916)
> I would point to MongoDB's query language

seriuosly?

    db.orders.aggregate([
       {
          $lookup:
             {
               from: "warehouses",
               let: { order_item: "$item", order_qty: "$ordered" },
               pipeline: [
                  { $match:
                     { $expr:
                        { $and:
                           [
                             { $eq: [ "$stock_item",  "$$order_item" ] },
                             { $gte: [ "$instock", "$$order_qty" ] }
                           ]
                        }
                     }
                  },
                  { $project: { stock_item: 0, _id: 0 } }
               ],
               as: "stockdata"
             }
        }
    ])
VS

    SELECT *, stockdata
    FROM orders
    WHERE stockdata IN (SELECT warehouse, instock
                        FROM warehouses
                        WHERE stock_item= orders.item
                        AND instock >= orders.ordered );
Re:We Can Do Better Than SQL by petepete on Tuesday August 11, 2020 @11:10AM (#24121109)
Another huge win for SQL is that it's easy to construct from parts. You can very easily run and debug your subquery or common table expression on its own before combining it into a larger, more-complex query. If you (as I usually do) create plenty of views while analysing a dataset, the approach can be extremely powerful.

Doing the same in JavaScript is possible, but it's slow and cumbersome by comparison.

Re:We Can Do Better Than SQL by 013a on Tuesday August 11, 2020 @01:55PM (#24123452)
The original article addresses the deficiency in construction from parts, in its "Lack of Orthogonality" section.

MongoDB queries, while being interpretable by javascript, aren't really javascript. You can't interact with the data using javascript (well, you can, using eval, but you shouldn't). You interact with the data via the query language, which is, again, expressed in JS, just like SQL is expressed in English.

It's more accurate to consider the Aggregation Pipeline as being the "composable" system to get at data in MongoDB. And its exceedingly composable; far more than SQL. It's literally a pipeline; a series of steps which fetch, mutate, filter, map, limit, calculate, correlate, relate, and otherwise interact with the data in a database. Each step operates on the output of the previous step, in series. You can programmatically swap steps in-and-out, in production, with no string manipulation or ORM, debug each step in series, remove steps, see the output, get performance characteristics on each step. There's no complex black-boxed query execution planner or compiler, because the query plan is the pipeline.

Re:We Can Do Better Than SQL by lostjohnny on Thursday August 13, 2020 @09:30AM (#24143123)
> with no string manipulation or ORM

OR, another way to look at it, using MongoDB's ORM, which is quite bad if you ask me.

Re:We Can Do Better Than SQL by 013a on Tuesday August 11, 2020 @11:18AM (#24121204)
If you try to directly translate SQL to MongoDB, without changing your schemas or query, then yes, it's gonna look bad. That doesn't make for a good comparison, and I think you know that.
Re:We Can Do Better Than SQL by lostjohnny on Thursday August 13, 2020 @09:26AM (#24143079)
> That doesn't make for a good comparison, and I think you know that.

That query is not my invention, it comes directly from MongoDB documentation

If it looks bad, it means it is bad by design

https://docs.mongodb.com/manual/reference/operator/aggregati...

Re:We Can Do Better Than SQL by fortran77 on Tuesday August 11, 2020 @11:27AM (#24121323)
MongoDB is better because it's Web Scale!

http://www.mongodb-is-web-scale.com/

Re:We Can Do Better Than SQL by Beefin on Tuesday August 11, 2020 @11:53AM (#24121727)
you're comparing $lookup, an operator that nosql isn't designed for to a join, an operator sql was designed for
Re:We Can Do Better Than SQL by 013a on Tuesday August 11, 2020 @01:40PM (#24123213)
Lookups are very common in MongoDB; Starting with SQL, lifting the data as-is into Mongo, and translating the queries 1:1 will just result in garbage queries, like that one.

An "idealized" NoSQL schema is far, far more complex than anything anyone used to SQL would arrive at ([1]), but most of that is because in a "pure" NoSQL/Document-oriented database, the query engine simply isn't that powerful (think Dynamo). MongoDB has an inordinately powerful array of tools to get at data in a performant way, and $lookup is available as one of those tools. Can it be misused? Yeah; just look at the parent comment to see clear misuse. But generally, it's very common to see.

Modern thinking around MongoDB schema design is closer to SQL than NoSQL/Dynamo. Arrays are bad, denormalization can be valuable but use sparingly, that kind of stuff.

[1] https://docs.aws.amazon.com/amazondynamodb/latest/developerg...

Re:We Can Do Better Than SQL by Beefin on Tuesday August 11, 2020 @07:28PM (#24127132)
I wouldn't say arrays are bad, and the entire paradigm of data modeling in mongodb is to store your data based on your application usage patterns. if you have to query across multiple collections via a $lookup, then maybe you'd benefit from embedding the smaller of those collections into the former.
Re:We Can Do Better Than SQL by 013a on Tuesday August 11, 2020 @07:43PM (#24127234)
Maybe. But, as a general rule, I advise against arrays of unbounded size on documents (arrays of a known bounded size, say, containing enums to act as a multi-value flag, or email addresses on a user's account, or something like that, are fine).

One example: We used mongodb to track the state of a general CSV import system. So, we'd have a document for each csv file a user imported, and on that document, we were storing errors which occurred during the import to later display to the user. Of course, in an array. Worked great for years, until one day, a user uploaded a very bad CSV, non-maliciously, with hundreds of thousands of lines, with dozens of errors on each line, generating an array millions of items large. The failure condition here was wild: the import just got slower, and slower, and slower, until eventually the (modestly provisioned) db cluster started failing. We immediately normalized that array into its own collection, re-ran the import, still generated millions of errors, but with no problem.

As always, a general rule doesn't apply in every situation, but in my experience, unless you have a really strong grasp on how a system's use will scale, years into the future, unbounded arrays are icky. Lookups across two collections are only a modest performance loss over a direct query, and if the arrays get up there in size, they can actually be faster.

Re:We Can Do Better Than SQL by emptysea on Tuesday August 11, 2020 @08:27PM (#24127471)
Interesting, we ran into a very similar thing at my current place where we have a CSV importer storing results in mongo. Importantly it also stores the errors that occurred during the import.

In our case someone uploaded a _huge_ CSV with some misalignment in the columns so every row had an error.

The resulting the mongo document was larger the max document size (16MB?), so it couldn't even save to the database.

Mongo is painful to work with and I feel like I keep finding more reasons to hate it.

Re:We Can Do Better Than SQL by sfvisser on Tuesday August 11, 2020 @02:42AM (#24117759)
> SQL is messy because describing the underlying data relationships are messy.

Not sure that is true. You can imagine having a smaller query language with clean semantics able to capture messy data relationships. Small functional expression languages come to mind. Where it lies on the spectrum from purely-table-form to can-hold-everything is a design choice.

Your query language doesn’t need to capture the underlying data model exactly. SQL is an example of this itself.

I’ve run into the orthogonality issue myself several times. You don’t need to drop SQL today, but for some data domains more expressive query models can work really well.

Re:We Can Do Better Than SQL by Areading314 on Tuesday August 11, 2020 @03:21AM (#24117974)
Right, it's like criticizing python, or English, for being inconsistent, or "large". Turns out that doesn't matter -- what matters is that the language is useful because it has a wide base of users and libraries, just like SQL does.
Re:We Can Do Better Than SQL by m000 on Tuesday August 11, 2020 @06:26AM (#24118903)
Python and English are meant to be general purpose languages, so they are kind of expected to be large and occasionally inconsistent. SQL is (by definition) a domain-specific language which has grown out of proportions.

Are there really any SQL libraries in the traditional sense (i.e. reusable/composable SQL code with a well specified API)? SQL "libraries" typically focus on hiding the inconsistencies and the abhorrent syntax under the carpet.

And the user base is there, mostly because of the database engine properties and features. The query language itself is just a bad side-effect. And TFA does make a point that NoSQL abandoning the underlying RDBMS model is in fact a regression.

Re:We Can Do Better Than SQL by bmh100 on Tuesday August 11, 2020 @11:21AM (#24121237)
SQL is designed around databases. Python is designed around objects. Clojure is designed around expressions. A table is analogous to a list of objects. None of these languages is more domain-specific than any other.
Re:We Can Do Better Than SQL by Areading314 on Tuesday August 11, 2020 @01:46PM (#24123315)
Perhaps libraries doesn't really apply to SQL per se, but instead you have tooling, ecosystem, DB engines, ORMs, extensions etc, that all speak SQL and would be hard to do without.
Re:We Can Do Better Than SQL by asdfasgasdgasdg on Tuesday August 11, 2020 @09:50AM (#24120201)
SQL is messy because describing the underlying data relationships are messy.

The article presents several examples where SQL's messiness cannot be plausibly attributed to underlying data relationship messiness.

Re:We Can Do Better Than SQL by wtetzner on Tuesday August 11, 2020 @11:58AM (#24121799)
I think the real problem is that SQL text is the only interface to most relational databases. There is a SQL standard, of course, but it's difficult to get vendors to implement the standard, because SQL is the user interface to the database.

Instead, perhaps a second format should be standardized, which is machine readable/writable, that more or less represents relational algebra + whatever extra features SQL supports. It can be clunky and verbose, as long as it's straight-forward and easily composable. It would effectively be like a compiler intermediate representation.

Once you have something like that, you can have as many front-ends as you want with whatever syntax you prefer.

Of course, getting all of the RDBMS vendors to agree to it is still a problem, and they'll probably all still include their own vendor-specific extensions and differences, because they want to lock you in to their system.

But at least maybe the open source ones could agree, which would still be quite beneficial.

Re:We Can Do Better Than SQL by IshKebab on Tuesday August 11, 2020 @03:55AM (#24118173)
I don't see how that makes them arrogant. SQL's implementation inconsistencies are a real problem. Their query language doesn't claim to be another version of SQL - it's clearly very different.

Also that is only one of the things they are hoping to fix. It sounds like you're saying "We have 5 variants of SQL already so nobody is allowed to write any other database query languages ever. We must use SQL forever." which is stupid.

Re:We Can Do Better Than SQL by gwbas1c on Tuesday August 11, 2020 @07:25AM (#24119192)
In a world where there's a new programming language every other month, what's wrong with suggesting a new query language?

At least we don't have to change our whole data model or give up consistent data to try it!

Re:We Can Do Better Than SQL by joshsyn on Tuesday August 11, 2020 @10:00AM (#24120301)
Most relationships, I have encountered are just one-many, many-one, many-mane, one-one, indirect, direct or graphical in nature.

You want flat result, aggregated result. Why does this have to be blamed on the data relationship and not SQL language itself?

For any graphical type of relationships, I find SQL utterly hard to express my queries properly. It feels like a assembly language at that point.

Re:We Can Do Better Than SQL by xiaodai on Tuesday August 11, 2020 @01:44AM (#24117497)
yeah the edgeql syntax just looks messy and the doc doesn't even explain how to do a group by
Re:We Can Do Better Than SQL by lowwave on Wednesday August 12, 2020 @03:45AM (#24129553)
It is very common to hear from new developers who are not familar with declaritve programming to complain about SQL. They don't tend to see the SQL syntqax fit into their 'programming' paradim. It is very simple, SQL is magic box, you ask it what you want, and it gave it to you. It is around for so long for a reason.
Re:We Can Do Better Than SQL by quickthrower2 on Tuesday August 11, 2020 @02:46AM (#24117773)
I was hoping for something more left field myself. If SQL is based on tables, what about a QL based on relations only. Columns of data that are related, the "TABLE" implementation detail doesn't need to factor into it.
Re:We Can Do Better Than SQL by cmrdporcupine on Tuesday August 11, 2020 @11:25AM (#24121286)
I think you might be misunderstanding what a relation is in the relational algebra or relational db. It's not a relationship. A relation is nothing more than a set of sets. Tables are relations, and views are relations. The results of queries are also relations.

This is a common misunderstanding of what the relational in "relational database" means. It's not (primarily) about relationships, except insofar that relationships can be described using relations and queried using relational algebra. But the key concept is that of the mathematical relation, as per Wikipedia:

"In mathematics, an n-ary relation on n sets, is any subset of Cartesian product of the n sets (i.e., a collection of n-tuples)"

So the goal of relational db languages is to provide tools for querying these sets of sets. Joins, Unions, Selections (Restrictions), and Projections are some of the tools that are provided. SQL provides some of these, though often calls them confusing names.

For example, in SQL the "select" keyword begins the query statement, but selection proper (as per relational algebra, also called restriction) is actually what is expressed in the "where" clause. What comes after "select" in your query is technically "projection" (choosing which tuples/columns exist in the output). Many ORMs and similar tools get this messed up, because the authors of them know SQL, but not the relational algebra on which it is nominally based.

Re:We Can Do Better Than SQL by jeltz on Tuesday August 11, 2020 @07:29AM (#24119222)
Isnvt that true for SQL? SQL treats everything as a relation and does not make any difference between a table, a view, a set returning function, a sub query or a CTE.
Re:We Can Do Better Than SQL by dragonwriter on Tuesday August 11, 2020 @02:52AM (#24117823)
> If SQL is based on tables, what about a QL based on relations only.

Aside from DDL (which I'm not sure how you would do without distinguishing between base relvars [tables], derived relvars [views], and other classes of relations), SQL doesn't particularly treat different kinds of relation differently beyond what is minimally necessary (you can't write, via insert or update, to a relation that isn't a relvar, for instance.)

Re:We Can Do Better Than SQL by iddan on Tuesday August 11, 2020 @03:58AM (#24118188)
This is what we are trying to do with Cayley https://github.com/cayleygraph/cayley
Re:We Can Do Better Than SQL by woile on Tuesday August 11, 2020 @04:38AM (#24118398)
The website needs a link to the documentation, I just couldn't find it :/
Re:We Can Do Better Than SQL by rplst8 on Tuesday August 11, 2020 @05:52AM (#24118749)
> If SQL is based on tables, what about a QL based on relations only.

Try Sparql.

Re:We Can Do Better Than SQL by udp on Tuesday August 11, 2020 @08:00AM (#24119407)
Came looking for the reference, and found it - but there are fewer and fewer mentions of SPARQL with each of these HN discussions. I think people just think "oh some semantic web crap" and move on without realising how powerful RDF etc. really can be when used as simple tools, without the 90s hype of changing the world with linked data.

At least the old ideas are resurging in the form of Neo4j (essentially a triplestore) and Cypher (essentially SPARQL).

Re:We Can Do Better Than SQL by tasubotadas on Tuesday August 11, 2020 @06:17AM (#24118860)
Re:We Can Do Better Than SQL by p4bl0 on Tuesday August 11, 2020 @04:58AM (#24118505)
Are you thinking of Datalog?
Re:We Can Do Better Than SQL by oarabbus_ on Tuesday August 11, 2020 @01:30PM (#24123034)
>In that case, the result set is no longer a table, it's a dataframe, which is a useful data structure but is also not what relational databases do.

What do you mean here? The difference between a table and a dataframe is that a dataframe is a construct held in memory, while a table is persisted storage written to a database.

Re:We Can Do Better Than SQL by unityByFreedom on Tuesday August 11, 2020 @02:52AM (#24117820)
I completely agree with both the title of this post and your comment. The solution is in diagrammatic "languages"/tools like Airflow, not more query languages.

Selecting columns before tables always felt weird to me. Doesn't it make more sense if you had a graphical view this way? (imagine boxes around the below items where you can drag lines to make connections between tables/inputs)

    USERS
           --user_id-- [data processing] => ...
    GROUPS
In SQL that would be,

SELECT * ,groups.* from users INNER JOIN groups ON users.user_id = groups.user_id

SQL is so messy and full of details that can be much better represented via dataflow diagrams.

Re:We Can Do Better Than SQL by tsimionescu on Tuesday August 11, 2020 @03:32AM (#24118044)
Given our source control tools' limitations, I will take a textual format over graphical representation any day.

Either way, queries need to be composed at runtime a lot of the time, so for many uses of SQL you can't just have the queries as blobs that you prepare ahead of time in some other tool - they must be objects you can work with programmatically.

Re:We Can Do Better Than SQL by cafard on Tuesday August 11, 2020 @08:26AM (#24119573)
Somebody at work just stepped a Microsoft Dynamics "integration". The network admin is trying to recover the integration database from a snapshot. An integration maps data from external files into accounting structures: it uses a GUI, with names that make sense to accountants. And the database that holds it is an Access database with the integration details in a BLOB. I'd pay money for a tool to save these out to a textual representation we could put under source control.
Re:We Can Do Better Than SQL by unityByFreedom on Tuesday August 11, 2020 @08:37AM (#24119632)
There's no reason a diagram can't be in source control. You just need a tool that can convert the diagram to code and the code to a diagram. You probably also want to store the diagram's layout in textual form too so it can be converted back to the original human-created layout.

Then you can use git and optionally build custom tools like a visual diff of diagram v1 vs v2.

Re:We Can Do Better Than SQL by tsimionescu on Tuesday August 11, 2020 @09:21AM (#24119996)
The diff tool is the key here. Without that, there is no meaningful version control.
Re:We Can Do Better Than SQL by unityByFreedom on Tuesday August 11, 2020 @09:59AM (#24120293)
With a visual representation, diffing may be as easy as clicking next/previous between versions as you would images in an album. You could of course add more bells and whistles with highlighting.
Re:We Can Do Better Than SQL by tsimionescu on Tuesday August 11, 2020 @04:23PM (#24125539)
Sorry, I should have been more specific. When I say diffing tool, I mean one that can do what diff does - help Git do automatic merges, and help me do manual merges when auto merge finds conflicts. Two pictures side by side can do neither.
Re:We Can Do Better Than SQL by unityByFreedom on Tuesday August 11, 2020 @07:06PM (#24127008)
I don't see why it couldn't be built. Git merge doesn't always do all the work for you, you still need to evaluate the changes.
Re:We Can Do Better Than SQL by 83457 on Tuesday August 11, 2020 @03:02AM (#24117872)
There are graphical query generators in at least Microsoft's management tools. Most devs use straight SQL as far as I know because once you get into more complex queries the graphical interface becomes a hassle.
Re:We Can Do Better Than SQL by unityByFreedom on Tuesday August 11, 2020 @03:13AM (#24117931)
> There are graphical query generators in at least Microsoft's management tools

The dev still needs to type the code first, which does not address any problems with SQL.

> Most devs use straight SQL as far as I know because once you get into more complex queries the graphical interface becomes a hassle.

Those interfaces may be limited, or the devs may not have enough experience writing "code" via a higher-level graphical interface. Going from writing SQL to creating dataflow diagrams may be a bit like switching from imperative to functional programming.

Re:We Can Do Better Than SQL by cmrdporcupine on Tuesday August 11, 2020 @11:50AM (#24121681)
"Selection" in the relational algebra is actually everything that comes after the WHERE clause. SQL confuses people here because "SELECT" seems to imply "select these columns" when in fact that is technically called "projection."

The "Selection" is the set of predicates that restrict the resulting relation. Projection is choosing which tuples ("columns") to use in it.

The relational algebra has no "tables", this is, again, a SQL thing. It has relations (sets of sets) and operations on them. In SQL "tables" are one kind of relation, and views are another.

Re:We Can Do Better Than SQL by josefrichter on Tuesday August 11, 2020 @06:37AM (#24118961)
the first paragraph of your response was unnecessary, or perhaps could have been worded more constructively
Re:We Can Do Better Than SQL by enjo on Tuesday August 11, 2020 @01:49AM (#24117511)
XKCD’s comic on competing standards feels appropriate here:

https://xkcd.com/927/

Re:We Can Do Better Than SQL by CodesInChaos on Tuesday August 11, 2020 @08:10AM (#24119458)
I don't think treating query languages as a standard is the right comparison here. I think it's great that programming languages have evolved from C or PHP quality languages. I view SQL like PHP, I can write it if I have to, but it's certainly not a language I enjoy working with. EdgeQL has its flaws, but it still looks like a big improvement over SQL to me.
Re:We Can Do Better Than SQL by WesleyJohnson on Tuesday August 11, 2020 @08:58AM (#24119801)
I must be in the minority. I enjoy writing SQL and figuring out clever ways to construct queries to get what I need out of the data. Conversely, I am not a fan of PHP at all, but as you said, will write it if I have to.

EdgeQL looks... interesting, but I need to see more to decide for sure. Would be cool if they built out a translator, so you could pass in SQL and get back EdgeQL.

Re:We Can Do Better Than SQL by CodesInChaos on Tuesday August 11, 2020 @11:31AM (#24121390)
It's a translator, but in the opposite direction. EdgeDB is a postgres frontend that translates EdgeQL and its schema definition language to SQL which it then sends to postgres. (It can also translate GraphQL to EdgeQL to SQL)

I don't think translating from SQL to take a look at the EdgeQL it produces makes much sense, since it'd result in very unidiomatic queries. SQL prefers joins and flat rows, while EdgeQL is based on following links and has great support for nested data output.

Re:We Can Do Better Than SQL by agumonkey on Tuesday August 11, 2020 @02:28AM (#24117684)
is xkcd ever not appropriate ? there's probably an xkcd about it
Re:We Can Do Better Than SQL by kybernetikos on Tuesday August 11, 2020 @05:22AM (#24118612)
Not a munroe original, but I like this one https://thomaspark.co/2017/01/relevant-xkcd/
Re:We Can Do Better Than SQL by agumonkey on Tuesday August 11, 2020 @06:08AM (#24118813)
oh I thought he did that :)
Re:We Can Do Better Than SQL by zadkey on Tuesday August 11, 2020 @11:48AM (#24121646)
Re:We Can Do Better Than SQL by bryanrasmussen on Tuesday August 11, 2020 @05:55AM (#24118758)
>It's pretty arrogant to complain about the syntax being inconsistent across versions and databases and then present your own weird offshoot, as if every other version wasn't introduced for the exact same reason with the exact same lofty delusions of grandeur...

Obligatory XKCD https://xkcd.com/927/