TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Simplifying Join Syntax

53 pointsby Judyrabbitabout 1 year ago

14 comments

david_pabout 1 year ago
I love the idea of a simplified SQL syntax for joins.<p>I have been working with graph databases for years now: these databases had to solve this problem from day one, because of the focus on relationships between entities.<p>I must point out that Neo4j was the first to propose a syntax that made traversal feel simple and natural again: the Cypher query language.<p>Neo4 and other industry players have spent years working on a new standard query language for graph databases that was released in April this year: GQL. GQL is the first database query language normalized by ISO since SQL, so it’s a big deal.<p>Anyway, if you wanna learn more about GQL, that a look at <a href="https:&#x2F;&#x2F;www.gqlstandards.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.gqlstandards.org&#x2F;</a>
评论 #40393593 未加载
评论 #40388901 未加载
评论 #40393358 未加载
评论 #40391894 未加载
funcDropShadowabout 1 year ago
The presented idea shortens the given examples, but is not composable. What happens if you have 1:N instead of 1:1 relation? Or even a N:M relation. Where do you specify whether you want an innner &#x2F; outer &#x2F; left &#x2F; right join? This proposal works for some simple queries but fails to capture the generality of the relational model.<p>So, from a language development point of view, one has to ask: Is this special case worth the extra syntactical sugar? It has the downside, that when a query evolves and falls out of the special case you have to reformulate the syntactical sugar yourself. This creates friction, and it is still necessary to understand the relational model.<p>Other commenters mentioned Neo4j as an example where similar ideas have been implemented. From my limited experience with Neo4j, I&#x27;d say it makes a lot of sense there, because graph queries will often fall into the sub class of queries, that can benefit from the syntactical sugar.<p>All in all, I would not call this a simplification. Syntactical sugar never is a simplification. It is an &quot;easification&quot;. It makes certain examples easy and hides what is going on, without really abstracting it away.
评论 #40388050 未加载
评论 #40393773 未加载
asplakeabout 1 year ago
“As all joins involve the primary key…”<p>Often but not always the case<p>Edit: at least not in SQL, and therefore SQL databases. If the language being described here isn&#x27;t actually SQL, that could still be a problem.
mawekiabout 1 year ago
This implicit JOIN feature is already present in HQL and also in Jooq. It&#x27;s very convenient, especially when you use a star-like table structure where the important data table is basically just IDs and references.<p><a href="https:&#x2F;&#x2F;www.jooq.org&#x2F;doc&#x2F;latest&#x2F;manual&#x2F;coming-from-jpa&#x2F;from-jpa-implicit-join&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.jooq.org&#x2F;doc&#x2F;latest&#x2F;manual&#x2F;coming-from-jpa&#x2F;from-...</a>
评论 #40391988 未加载
fjfaaseabout 1 year ago
I think it is important to realize that relational, object-oriented and structured data (such as XML and JSON) are all implementation of an often far more richer data model. Would it not be better to implement something for the richer data model, such that querying relational data models to produce JSON (for example) would become trivial?<p>A long time ago, I made some attempts about this: <a href="https:&#x2F;&#x2F;www.iwriteiam.nl&#x2F;AoP_spec_stat.html" rel="nofollow">https:&#x2F;&#x2F;www.iwriteiam.nl&#x2F;AoP_spec_stat.html</a> Not so long ago, I worked a bit on a data oriented language with cursors, compounds and components: <a href="https:&#x2F;&#x2F;github.com&#x2F;FransFaase&#x2F;DataLang">https:&#x2F;&#x2F;github.com&#x2F;FransFaase&#x2F;DataLang</a>.
bionhowardabout 1 year ago
Cool idea! I always thought this was the purpose of cypher match statements but your syntax is much shorter and more familiar dot-pathing<p>One idea would be for the x.y.z to use functions like<p>x.y(argument).z<p>This way you could parameterize the traversals and it’d wind up looking like gremlin in sql
评论 #40374609 未加载
twicabout 1 year ago
&gt; Both tables use id field as their primary keys. Managers are also employees, so the two tables share the ids. Since managers have more attributes, their information is stored in a separate table.<p>&gt; Now we want to find the total income (including the allowance) of each employee (including every manager).<p>&gt; A JOIN operation is necessary for SQL to do it:<p><pre><code> &gt; SELECT employee.id, employee.name, employy.salary+manager.allowance &gt; FROM employee &gt; LEFT JOIN manager ON employee.id=manager.id </code></pre> &gt; But for two tables having a one-to-one relationship, we can treat them like one table:<p><pre><code> &gt; SELECT id,name,salary+allowance &gt; FROM employee </code></pre> What about employees who aren&#x27;t managers? I assume they have no entry in the manager table. The SQL would ignore them, because it&#x27;s a left join, which is not what was asked for. Does the proposed query do the same?<p>What happens if there is also<p><pre><code> salesperson table id allowance </code></pre> ? Which table is joined?<p>This language seems a little half-baked.
beagle3about 1 year ago
A 30 year old implementation of the same idea (even slightly better IMHO) can be found in kdb+&#x2F;ksql&#x2F;shakti, you can see examples and comparison in <a href="https:&#x2F;&#x2F;shakti.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;shakti.com&#x2F;</a> (press document, then sql.d - no idea how to link directly). And yes, it is by Arthur Whitney and related to the [in]famous K
评论 #40394338 未加载
zerononeabout 1 year ago
jOOQ has similar feature<p><a href="https:&#x2F;&#x2F;www.jooq.org&#x2F;doc&#x2F;latest&#x2F;manual&#x2F;code-generation&#x2F;codegen-advanced&#x2F;codegen-config-generate&#x2F;codegen-implicit-join-paths&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.jooq.org&#x2F;doc&#x2F;latest&#x2F;manual&#x2F;code-generation&#x2F;codeg...</a>
评论 #40394026 未加载
alexisreadabout 1 year ago
Didn&#x27;t <a href="https:&#x2F;&#x2F;www.odata.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.odata.org&#x2F;</a> do this already? If the Odata server understands the table relations, you can navigate through table relations in the REST query. I found that most parts of the business prefer filtering more than joining, learning another DSL other than SQL was a real barrier, and that many BI tools only support a subset of Odata, so are pretty much useless.<p>I definitely prefer concatenative (monadic) syntax a la Linq though, as it allows better scoping of efficient joins without a planner - it allows you to duck-tape (allusion intended) together a platform service easily.
pavi2410about 1 year ago
SOQL in Salesforce supports &quot;relationship queries&quot; that works on both directions, viz, parent-to-child and child-to-parent.<p><a href="https:&#x2F;&#x2F;developer.salesforce.com&#x2F;docs&#x2F;atlas.en-us.soql_sosl.meta&#x2F;soql_sosl&#x2F;sforce_api_calls_soql_select_examples.htm" rel="nofollow">https:&#x2F;&#x2F;developer.salesforce.com&#x2F;docs&#x2F;atlas.en-us.soql_sosl....</a>
PeterZaitsevabout 1 year ago
There are many good ideas to improve SQL, though it is not easy to get traction as it is such an old standard with so many implementations
atemerevabout 1 year ago
See “natural join”, which already exists in SQL; I use it all the time.
评论 #40393414 未加载
评论 #40389132 未加载
tucnakabout 1 year ago
More geniuses trying to &quot;improve&quot; SQL, and yet the only party to succeed in doing this is Postgres people, of actual relational SQL database—by means of dialect.