logoalt Hacker News

ctippett • today at 11:53 AM • 3 replies • view on HN

If anything a well designed database minimises data duplication. If your query returns duplicate data that's on the writer, not the language's fault.


Replies

Skeime • today at 12:11 PM

It is the language's fault, because SQL offers no good way to get nested results. If you want to avoid the duplication, you can do multiple queries, but then you essentially have to do the join on the receiving end, which kind of defeats the purpose of having joins in SQL.

Alternatively, you might use functions to aggregate in the query, but they're not standard, as far I know, which means that interfaces in programming languages often do not support them. The best bet might be aggregating into JSON, but this removes quite a bit of the type information that values in SQL usually carry. (Also, the aggregation functions are generally less pleasant to write than standard joins.)

➕ show 2 replies
achr2 • today at 1:45 PM

It minimizes data storage duplication, but not reading. The language does not have a simple way to receive unique records across N-1 joins.

imtringued • today at 3:13 PM

No, that's still the SQL languages' fault because you cannot return multiple tables in a single query.

Half the reason why ORMs have trouble has to do with the fact that you need to fetch has many relations via a second select.

Beyond that, it's the GPPL languages' fault that it doesn't support object or class fragments which are needed to support queries that return a subset of an object.

If people bothered fixing these two issues, then ORMs would be great.